日期:2012-12-11 浏览次数:20421 次
<?php
/*
* 这个类本来是PHPLIB里的一部分,我做了些修改。
*/
class MyDB_Sql {
var $Host = "";
var $Database = "";
var $User = "";
var $Password = "";
var $Link_ID = 0;
var $Query_ID = 0;
var $Record = array();
var $Row;
var $Errno = 0;
var $Error = "";
var $Auto_free = 0; ## Set this to 1 for automatic mysql_free_result()
var $Auto_commit = 0; ## set this to 1 to automatically commit results
var $debugmode = 0;
function connect() {
if ( 0 == $this->Link_ID ) {
$this->Link_ID=mysql_pconnect($this->Host, $this->User, $this->Password);
if (!$this->Link_ID) {
$this->halt("Link-ID == false, pconnect failed");
}
if (!mysql_query(sprintf("use %s",$this->Database),$this->Link_ID)) {
$this->halt("cannot use database ".$this->Database);
}
}
}
function query($Query_String) {
$this->connect();
if ($this->debugmode)
printf("Debug: query = %s<br>\n", $Query_String);
$this->Query_ID = mysql_query($Query_String,$this->Link_ID);
$this->Row = 0;
$this->Errno = mysql_errno();
$this->Error = mysql_error();
if (!$this->Query_ID) {
$this->halt("Invalid SQL: ".$Query_String);
}
return $this->Query_ID;
}
function next_record() {
$this->Record = mysql_fetch_array($this->Query_ID);
$this->Row += 1;
$this->Errno = mysql_errno();
$this->Error = mysql_error();
$stat