标题: [有亮点]一个简单的数据库操作类
时间: 2014-06-22
<?php
/*
@MYSQL连接类
*/
class QeeZer_Mysql
{
private $host;
private $user;
private $pass;
private $conn;
private $db;
function __construct($host,$user,$pass,$db)
{
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->db = $db;
$this->conn = @mysql_connect($this->host,$this->user,$this->pass) or die('//数据库链接失败输出错误
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>数据库连接错误</title>
<link rel="stylesheet" href="templates/css/wap.css" type="text/css"></link>
</head>
<body>
<font color="red"><strong>数据库连接错误</font>
</body>
</html>');
@mysql_select_db($this->db) or die('dbFalse');//选择数据库失败输出错误
@mysql_query("set names 'utf8'");
}
//执行数据库语句
public function query($sql)
{
return mysql_query($sql);
}
//打印数据库语句详情
public function setInfo($name,$line,$comment)
{
return array(
'name' => $name,
'file' => __FILE__,
'line' => $line,
'comment' => $comment
);
}
//页面数据库语句数量
public function sqls()
{
return count($this->setInfo);
}
function __destruct()
{
if($this->conn)
{
mysql_close($this->conn);
}
}
}
『回复列表(5|隐藏机器人聊天)』