Practical and simple MySQL Tutorial database Tutorial Connection Class
Class DB
{
Database connection
var $con = FALSE;
function DB ($MYSQL _host=mysql_host, $MYSQL _user=mysql_user, $MYSQL _pass=mysql_pass, $MYSQL _db=mysql_db)
{
$this->con = @mysql_connect ($MYSQL _host, $MYSQL _user, $MYSQL _pass) or Die ("Could is connect to database");
if ($this->con)
{
@mysql_select_db ($MYSQL _db, $this->con) or Die ("Could not select Database");
}
return $this->con;
}
function Query ($sql, $tran = False)
{
if (!file_exists (Mysql_log))
// {
@umask (0);
@mkdir (Mysql_log, 0777);
// }
¼־
$fp = @fopen (Mysql_log.date ("YMD"). ". TXT "," a ");
Д־
@fwrite ($fp, Date ("Y-m-d h:i:s"). "| $sqlrn ");
@fclose ($FP);
$this->sql = $sql;
if ($tran)
{
$this->result = @mysql_query ($this->sql) OR $this->rollback ();
return $this->result;
}
Else
{
mysql_query ("SET NAMES ' UTF8 '");
mysql_query ("SET NAMES ' GBK '");
$this->result = @mysql_query ($this->sql);
return $this->result;
}
}
function RollBack ()
{
$this->query ("ROLLBACK;");
Die ("MySQL ROLLBACK;");
}
function NumRows ($result)
{
$this->result = $result;
Return @mysql_num_rows ($this->result);
}
function Fetchrow ($result)
{
$this->result = $result;
Return @mysql_fetch_row ($this->result);
}
function Fetcharray ($result)
{
$this->result = $result;
Return @mysql_fetch_array ($this->result, MYSQL_ASSOC);
}
function FetchArray2 ($result)
{
$this->result = $result;
Return @mysql_fetch_array ($this->result, Mysql_both);
}
function Fetchobject ($result)
{
$this->result = $result;
Return @mysql_fetch_object ($this->result);
}
function Freeresult ($result)
{
$this->result = $result;
Return @mysql_free_result ($this->result);
}
function Dataseek ($result)
{
Reset Recordset pointer
$this->result = $result;
Return Mysql_data_seek ($this->result,0);
}
function Insertid ()
{
$this->con = $con;
Return @mysql_insert_id ($this->con);
}
function Close ()
{
if ($this->con)
{
@mysql_close ($this->con);
}
}
}
http://www.bkjia.com/PHPjc/630886.html www.bkjia.com true http://www.bkjia.com/PHPjc/630886.html techarticle a practical and simple MYSQL Tutorial Database tutorial connecting classes class DB {//database connection var $con = FALSE; function DB ($MYSQL _host=mysql_host, $MYSQL _us Er=mysql_user, $MYSQL _pass=mysql ...