解析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;
}
?>

相关文章

php获取mysql版本的几种方法小结

select VERSION()  当前$res=mysql_query("select VERSION()");$row=mysql_fetch_row(...

PHP的mysqli_query参数MYSQLI_STORE_RESULT和MYSQLI_USE_RESULT的区别

虽然nosql变得流行,但是我感觉sql还是主流 今天在翻php manul的时候,发现mysqli 的查询可以传递一个有意思的参数 复制代码 代码如下: @mysqli_query($...

php更新mysql后获取影响的行数发生异常解决方法

从manual上知道了mysql_affected_rows函数当UPDATE前后的数据一样时会返回异常值, 下面有个方便的解决办法,从官方munual上看到 bdobrica at g...

php的慢速日志引起的Mysql错误问题分析

在我们的项目中,开启PHP的慢速日志(request_slowlog_timeout = 10s)是必选项,并且它也让我们发现了很多坑,解决了很多的性能问题。 昨天由于碰到了一个非常奇怪...

支持php4、php5的mysql数据库操作类

前端一直使用PHP5,的确使用起来特别的爽,现在为了能在俺的虚拟主机上跑,不得不改成PHP4的。这几个库类我以前发在PHPCHIAN,地址是http://www.phpchina.com...