解析link_mysql的php版

yipeiwu_com6年前Mysql基础

复制代码 代码如下:

<?php
$str_sql_read="select count(*) as num from userinfo";
$str_sql_del="delete from userinfo where id =1";
$res =link_mysql("read",$str_sql_read);
$res_del =link_mysql("delete",$str_sql_del);
echo $res_del."<br/>";
while($row = mysql_fetch_assoc($res))
{
 echo "<font style='font-size:25px;color:red;'>".$row['num']."</font><br/>";
}

?>

<?php
function link_mysql($opt,$str_sql)
{
 $con = mysql_connect("localhost","root","root") or die ('Not connected : ' . mysql_error());
 mysql_set_charset("gbk",$con);
 //if you donot know how to use this function,find it defination;
 mysql_select_db("website",$con);
 switch($opt){
  case "read":
   $res =mysql_query($str_sql);
  break; 
  case "update":
  case "delete":
  case "insert":
   $res =mysql_query($str_sql);
  break;   
 }
 mysql_close();
 return $res;
}
?>

相关文章

How do I change MySQL timezone?

However, there are ways for you to get results t...

php+mysqli实现批量执行插入、更新及删除数据的方法

本文实例讲述了php+mysqli实现批量执行插入、更新及删除数据的方法。分享给大家供大家参考。具体如下: mysqli批量执行插入/更新/删除数据,函数为 multi_query()。...

PHP开发环境配置(MySQL数据库安装图文教程)

PHP开发环境配置(MySQL数据库安装图文教程)

一、 MySQL的安装 运行MYSQL安装程序(mysql-essential-5.1.40-win32.msi)   选择安装类型为Custom   点选Cha...

在php MYSQL中插入当前时间

NOW()函数以`'YYYY-MM-DD HH:MM:SS'返回当前的日期时间,可以直接存到DATETIME字段中。 CURDATE()以'YYYY-MM-DD'的格式返回今天...

PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法

本文实例讲述了PHP提示 Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,在PHP程序开发中常会遇...