复制代码 代码如下:
<?php
require_once 'sqlTools.class.php';//封装类,可执行dql、dml语句
$info=$_POST['info'];
$sql="select name,password,email from user_500 where name like '%$info%' or password like '%$info%' or email like '%$info%'";
$sqlTools=new SqlTools();
$res=$sqlTools->execute_dql($sql);
while ($row=mysql_fetch_assoc($res)){
$row['name']=preg_replace("/($info)/i","<b style=/"color:red/">//1</b>",$row['name']);
$row['password']=preg_replace("/($info)/i","<b style=/"color:red/">//1</b>",$row['password']);
$row['email']=preg_replace("/($info)/i","<b style=/"color:red/">//1</b>",$row['email']);
echo $row['name']."-->".$row['password']."-->".$row['email']."<br>";
}
?>
复制代码 代码如下:
<?php
class SqlTools{
private $host="localhost";
private $dbname="test";
private $dbuser="root";
private $dbpwd="";
private $conn;
public function __construct(){
$this->conn=mysql_connect($this->host,$this->dbuser,$this->dbpwd);
if(!$this->conn){
die("连接数据库失败".mysql_error());
}
mysql_select_db($this->dbname,$this->conn) or die("找不到该数据库".mysql_error());
mysql_query("set names utf8");
}
public function execute_dml($sql){
$bool=mysql_query($sql);
if ($bool){
if ($bool>0) {
return 1;
}else{
return 2;
}
}else {
return 0;
}
}
public function execute_dql($sql){
$res=mysql_query($sql);
return $res;
}
public function close_conn(){
mysql_close($this->conn);
}
}
?>
新闻热点
疑难解答