php操作mySQL的简单类
时间:2006-11-17 来源:bridge2006
dbname = $dbname;
$this->host = $host;
$this->user = $user;
$this->passwd = $passwd;
}
//连接到mysql
function connect() {
$this->linkid = mysql_connect($this->host,$this->user,$this->passwd);
if (!$this->linkid)
{
die("Could not connect to mysql " . mysql_error());
}
$select_db = mysql_select_db($this->dbname,$this->linkid);
if (!$select_db)
{
die("Could not select db " . mysql_error());
}
}
//执行查询,返回查询结果
function query($query) {
$this->result = mysql_query($query,$this->linkid);
if (!$this->result) {
die($query . "
" . mysql_error());
}
return $this->result;
}
//返回最近影响的行数
function affected_rows() {
$count = mysql_affected_rows($this->linkid);
return $count;
}
//返回结果的总计行数
function num_rows() {
$count = mysql_num_rows($this->result);
return $count;
}
//返回一行作为对象
function fetch_object() {
$row = mysql_fetch_object($this->result);
return $row;
}
//返回一行作为关联数组
function fetch_assoc() {
$row = mysql_fetch_assoc($this->result);
return $row;
}
}
?>
$this->host = $host;
$this->user = $user;
$this->passwd = $passwd;
}
//连接到mysql
function connect() {
$this->linkid = mysql_connect($this->host,$this->user,$this->passwd);
if (!$this->linkid)
{
die("Could not connect to mysql " . mysql_error());
}
$select_db = mysql_select_db($this->dbname,$this->linkid);
if (!$select_db)
{
die("Could not select db " . mysql_error());
}
}
//执行查询,返回查询结果
function query($query) {
$this->result = mysql_query($query,$this->linkid);
if (!$this->result) {
die($query . "
" . mysql_error());
}
return $this->result;
}
//返回最近影响的行数
function affected_rows() {
$count = mysql_affected_rows($this->linkid);
return $count;
}
//返回结果的总计行数
function num_rows() {
$count = mysql_num_rows($this->result);
return $count;
}
//返回一行作为对象
function fetch_object() {
$row = mysql_fetch_object($this->result);
return $row;
}
//返回一行作为关联数组
function fetch_assoc() {
$row = mysql_fetch_assoc($this->result);
return $row;
}
}
?>
相关阅读 更多 +
排行榜 更多 +