解析link_mysql的php版

yipeiwu_com5年前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;
}
?>

相关文章

用phpmyadmin更改mysql5.0登录密码

update mysql.user set password=old_password('新密码') where user='用户名'&...

phpmyadmin MySQL 加密配置方法

以版本phpMyAdmin-2.6.1.tar.gz为例 先解压phpMyAdmin-2.6.1.tar.gz到/usr/local/apache2/htdocs, 得到文件夹phpMy...

PHP使用mysql与mysqli连接Mysql数据库用法示例

PHP使用mysql与mysqli连接Mysql数据库用法示例

本文实例讲述了PHP使用mysql与mysqli连接Mysql数据库的方法。分享给大家供大家参考,具体如下: 代码很简单直接上了 <?php /** * @Au...

mysql_fetch_assoc和mysql_fetch_row的功能加起来就是mysql_fetch_array

mysql_fetch_assoc只能用字段,就像mysql_fetch_array($result, MYSQL_ASSOC)结果一样。 mysql_fetch_row&nb...

PHP中addslashes与mysql_escape_string的区别分析

本文实例分析了PHP中addslashes与mysql_escape_string的区别。分享给大家供大家参考,具体如下: 1.在插入数据时两者的意义基本一样.区别只在于addslash...