时间:2021-07-01 10:21:17 帮助过:41人阅读
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","\\1",$row['name']);
$row['password']=preg_replace("/($info)/i","\\1",$row['password']);
$row['email']=preg_replace("/($info)/i","\\1",$row['email']);
echo $row['name']."-->".$row['password']."-->".$row['email']."
";
}
?>
代码如下:
class SqlTools{
private $host="localhost";
private $dbname="test";
private $dbuser="root";
private $dbpwd="";
private $conn;
public function __construct(){
$this->c
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);
}
}
?>
以上就介绍了显示 php站内搜索并高亮显示关键字的实现代码,包括了显示方面的内容,希望对PHP教程有兴趣的朋友有所帮助。