<?php
class db {
function connect($host, $user, $pwd, $db) {
if(@mysql_connect($host, $user, $pwd)) {
$this->select_db($db);
} else {
$this->slip('Connecting MySql server break!');
}
}
function select_db($db) {
return mysql_select_db($db);
}
function query($sql) {
$query = mysql_query($sql);
if(!$query) {
$this->slip('MySQL Query Error', $sql);
}
return $query;
}
function fetch_array($sql, $type = MYSQL_ASSOC) {
return mysql_fetch_array($sql, $type);
}
function affected_rows() {
return mysql_affected_rows();
}
function num_rows($query) {
return mysql_num_rows($query);
}
function num_fields($query) {
return mysql_num_fields($query);
}
function insert_id($query) {
return mysql_insert_id($query);
}
function result($query, $row) {
$query = @mysql_result($query, $row);
return $query;
}
function free_result($query) {
return mysql_free_result($query);
}
function close() {
return mysql_close();
}
function error() {
return mysql_error();
}
function errno() {
return mysql_errno();
}
function slip($info = '', $sql = '') {
echo '<b>'.$info.'</b>';
echo '<br />';
echo 'Mysql Error: '.$this->error();
echo '<br />';
echo 'Error Num. : '.$this->errno();
if($sql) {
echo '<br />';
echo 'Error SQL : '.$sql;
}
exit;
}
}
?>
本文地址:http://com.8s8s.com/it/it23396.htm