解析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获取表字段名称和字段信息的三种方法

php mysql获取表字段名称和字段信息的三种方法

php mysql获取表字段名称和字段信息的三种方法 先给出本实例中使用的表的信息: 使用desc获取表字段信息 php代码如下: <?php mysql_co...

解决PHP mysql_query执行超时(Fatal error: Maximum execution time …)

【错误原因】:mysql_query执行超时.【解决办法】:修改php.ini中的 max_execution_time的值,默认为300,单位是秒,例如:;max_execution_...

php数据入库前清理 注意php intval与mysql的int取值范围不同

php保存数据到mysql 打算在dao层进行数据入库前的清理,比如varchar进行trim,int进行intval。 有一天突然想起,php intval的取值范围与mysql的in...

PHP和Mysql中转UTF8编码问题汇总

一个网站如果需要国际化,就需要将编码从GB2312转成UTF-8,其中有很多的问题需要注意,如果没有转换彻底,将会有很多的编码问题出现! PHP页面转UTF-8编码问题 1.在代码开始出...

PHP实现的通过参数生成MYSQL语句类完整实例

本文实例讲述了PHP实现的通过参数生成MYSQL语句类。分享给大家供大家参考,具体如下: 这个类可以通过指定的表和字段参数创建SELECT ,INSERT , UPDATE 和 DELE...