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

相关文章

apache2.2.4+mysql5.0.77+php5.2.8安装精简

1.安装Apache 将httpd-2.2.4.tar.gz拷贝至/usr/local/src目录中 tar -zxvf httpd-2.2.4.tar.gz cd httpd-2.2....

在Windows XP下安装Apache+MySQL+PHP环境

在整个wamp环境搭建中,本质的工作如下: 1,配置系统对php中dll文件能默认处于调用状态。 在windos下,对dll文件系统默认处于调用状态的,有两种采用的方式。 第一种是:把...

mysql下创建字段并设置主键的php代码

复制代码 代码如下: mysql_select_db("hills_database_test",$dbcon); $alterpkadd="alter table hills_test...

如何设置mysql允许外网访问

mysql的root账户,我在连接时通常用的是localhost或127.0.0.1,公司的测试服务器上的mysql也是localhost所以我想访问无法访问,测试暂停. 解决方法: 1...

php基于PDO实现功能强大的MYSQL封装类实例

本文实例讲述了php基于PDO实现功能强大的MYSQL封装类。分享给大家供大家参考,具体如下: class CPdo{ protected $_dsn = "mysql:host=...