A practical and simple MySQL database connection class _php tutorial

Source: Internet
Author: User
Tags mysql tutorial
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.