/* Source: phpwind.net*/
Class DB {
var $query _num = 0;
function DB ($dbhost, $dbuser, $DBPW, $dbname, $pconnect = 0) {
$this->connect ($dbhost, $dbuser, $DBPW, $dbname, $pconnect);
}
Function Connect ($dbhost, $dbuser, $DBPW, $dbname, $pconnect = 0) {
$pc
Mysql_errno ()!=0 && $this->halt ("Connect ($pconnect) to MySQL failed");
if ($this->server_info () > ' 4.1 ' && $GLOBALS [' CharSet ']) {
mysql_query ("SET NAMES"). $GLOBALS [' CharSet ']. "'";
}
if ($this->server_info () > ' 5.0 ') {
mysql_query ("SET sql_mode=");
}
if ($dbname) {
if (! @mysql_select_db ($dbname)) {
$this->halt (' Cannot use database ');
}
}
}
function Close () {
return Mysql_close ();
}
function select_db ($dbname) {
if (! @mysql_select_db ($dbname)) {
$this->halt (' Cannot use database ');
}
}
function Server_info () {
return Mysql_get_server_info ();
}
function query ($SQL, $method = ") {
$GLOBALS [' PW ']== ' pw_ ' or $SQL =str_replace (' Pw_ ', $GLOBALS [' PW '], $SQL);
if ($method = = ' U_b ' && function_exists (' mysql_unbuffered_query ')) {
$query = Mysql_unbuffered_query ($SQL);
}else{
$query = mysql_query ($SQL);
}
$this->query_num++;
echo $SQL. '
'. $this->query_num. '
';
if (! $query) $this->halt (' Query Error: '. $SQL);
return $query;
}
function Get_one ($SQL) {
$query = $this->query ($SQL, ' u_b ');
$rs =& mysql_fetch_array ($query, MYSQL_ASSOC);
return $rs;
}
function Pw_update ($SQL _1, $SQL _2, $SQL _3) {
$rt = $this->get_one ($SQL _1);
if ($RT) {
$this->update ($SQL _2);
} else{
$this->update ($SQL _3);
}
}
function Update ($SQL) {
$GLOBALS [' PW ']== ' pw_ ' or $SQL =str_replace (' Pw_ ', $GLOBALS [' PW '], $SQL);
if ($GLOBALS [' DB_LP ']==1) {
if (substr ($SQL, 0,7) = = ' REPLACE ') {
$SQL =substr ($SQL, 0,7). ' Low_priority '. substr ($SQL, 7);
} else{
$SQL =substr ($SQL, 0,6). ' Low_priority '. substr ($SQL, 6);
}
}
if (function_exists (' mysql_unbuffered_query ')) {
$query = Mysql_unbuffered_query ($SQL);
}else{
$query = mysql_query ($SQL);
}
$this->query_num++;
echo $SQL. '
'. $this->query_num. '
';
if (! $query) $this->halt (' Update Error: '. $SQL);
return $query;
}
function Fetch_array ($query, $result _type = Mysql_assoc) {
Return mysql_fetch_array ($query, $result _type);
}
function Affected_rows () {
return Mysql_affected_rows ();
}
function Num_rows ($query) {
$rows = mysql_num_rows ($query);
return $rows;
}
function Free_result ($query) {
Return Mysql_free_result ($query);
}
function insert_id () {
$id = mysql_insert_id ();
return $id;
}
function Halt ($msg = ") {
Require_once (r_p. ' require/db_mysql_error.php ');
New Db_error ($MSG);
}
}
?>
The above describes the Phpwin phpwind in the database operation class, including the phpwin aspects of the content, I hope that the PHP tutorial interested in a friend helpful.