解析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将textarea数据提交到mysql出现很多空格的解决方法

本文实例讲述了php将textarea数据提交到mysql出现很多空格的解决方法。分享给大家供大家参考。具体分析如下: 有一些朋友可能会发现我们在html提交给php处理保存数据到mys...

php列出mysql表所有行和列的方法

本文实例讲述了php列出mysql表所有行和列的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:<html> <head> <title...

php 随机记录mysql rand()造成CPU 100%的解决办法

百度查阅了一些资料,再结合自己的一些经验,采用以下解决办法: 复制代码 代码如下: $idlist=''; for($i=1;$i<=20;$i++){ if($i==1){ $i...

php+mysql事务rollback&amp;commit示例

mysql_query("BEGIN");//开始一个事务 mysql_query("SET AUTOCOMMIT=0"); //设置事务不自动commit $insert="INSER...

Windows下IIS6/Apache2.2.4+MySQL5.2+PHP5.2.1安装配置方法

03年的时候就看过一本php的书,那时还是php3,回首四年php的在web开的的前景真还是一片光明啊!三年不见的php在去看已到了php5了,现在算起我真正从写第一个php的WEB开始...