解析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日期时间如何转换(UNIX时间戳和格式化日期)

写过PHP+MySQL的程序员都知道有时间差,UNIX时间戳和格式化日期是我们常打交道的两个时间表示形式,Unix时间戳存储、处理方便,但是不直观,格式化日期直观,但是处理起来不如Uni...

mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法

mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决...

php+mysql开发的最简单在线题库(在线做题系统)完整案例

php+mysql开发的最简单在线题库(在线做题系统)完整案例

本文实例讲述了php+mysql开发的最简单在线题库。分享给大家供大家参考,具体如下: 题库,对于教育机构,学校,在线教育,是很有必要的,网上也有不少的第三方在线题库系统,但是本次案例,...

解析csv数据导入mysql的方法

mysql自己有个csv引擎,可以通过这个引擎来实现将csv中的数据导入到mysql数据库中,并且速度比通过php或是python写的批处理程序快的多。具体的实现代码示例:复制代码 代码...

php中实现xml与mysql数据相互转换的方法

本文实例讲述了php中实现xml与mysql数据相互转换的方法。分享给大家供大家参考。具体分析如下: 这里提供了一个mysql2xml转换类,可以快速的把xml转换成mysql同时反之也...