MySQL Database connection class

Source: Internet
Author: User
Tags mysql query mysql tutorial php tutorial

MySQL Tutorial database Tutorial Connection Classes
This article provides a perfect PHP tutorial MySQL database connection class program, simple example.

*/
Class db{

var $linkid;
var $sqlid;
var $record;

function db ($host = "", $username = "", $password = "", $database = "")
{
if (! $this->linkid) @ $this->linkid = mysql_connect ($host, $username, $password) or Die ("Connection server failed.");
@mysql_select_db ($database, $this->linkid) or Die ("Unable to open database");
return $this->linkid;}

function query ($sql)
{if ($this->sqlid=mysql_query ($sql, $this->linkid)) return $this->sqlid;
else {
$this->err_report ($sql, mysql_error);
return false;}
}

function nr ($sql _id= "")
{if (! $sql _id) $sql _id= $this->sqlid;
Return mysql_num_rows ($sql _id);

function NF ($sql _id= "")
{if (! $sql _id) $sql _id= $this->sqlid;
Return Mysql_num_fields ($sql _id);

function NextRecord ($sql _id= "")
{if (! $sql _id) $sql _id= $this->sqlid;
if ($this->record=mysql_fetch_array ($sql _id)) return $this->record;
else return false;
}

function f ($name)
{
if ($this->record[$name]) return $this->record[$name];
else return false;
}

function Close () {mysql_close ($this->linkid);}

function Lock ($tblname, $op = "Write")
{if (mysql_query ("Lock Tables". $tblname. " ". $op)) return true; else return false;

function unlock ()
{if (mysql_query ("Unlock tables") return is true; else return false;}

function Ar () {
Return @mysql_affected_rows ($this->linkid);
}

function i_id () {
return mysql_insert_id ();
}

Function Err_report ($sql, $err)
{
echo "MySQL query error <br>";
Echo Query statement: ". $sql." <br> ";
Echo error message:. $err;
}

Related Article

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.