PHP connection MySQL database class _php tutorial

Source: Internet
Author: User
Tags mysql tutorial
PHP connection MySQL Database class This is a simple and practical PHP connection MySQL database class, only to do the data query, return the array set, get a new ID to get the record line, such as simple MySQL database connection code.

PHP Tutorial connecting MySQL Tutorial Database Tutorial class
This is a simple and practical PHP connection MySQL database class, only do the data query, return the array set, get the new ID get the record line and other simple MySQL database connection code.
*/

Class Database {

var $dblink;

Function Connect ($dbhost, $dbuser, $DBPW, $dbname = "") {
$this->dblink = mysql_connect ($dbhost, $dbuser, $DBPW);

mysql_query ("Set names ' UTF8 '");
mysql_query ("Set Character_set_client=utf8");
mysql_query ("Set Character_set_results=utf8");

if ($dbname) {
mysql_select_db ($dbname, $this->dblink);
}
}

function query ($sql) {
$result = mysql_query ($sql, $this->dblink);
return $result;
}

function Fetch_array ($result) {
return mysql_fetch_array ($result);
}

function insert_id () {
$id = mysql_insert_id ();
return $id;
}

function GetRow ($sql) {
$result = mysql_query ($sql, $this->dblink);
Return Mysql_fetch_assoc ($result);
}

function Getdetailrow ($sql) {
$result = mysql_query ($sql, $this->dblink);
return mysql_fetch_array ($result);
}
www.bKjia.c0m
function Close () {
Mysql_close ($this->dblink);
}
}

Calling methods

$db = new Database;
$db->connect ($dbhost, $dbuser, $DBPW, $dbname);
Unset ($dbhost, $dbuser, $DBPW, $dbname);


?>

http://www.bkjia.com/PHPjc/630805.html www.bkjia.com true http://www.bkjia.com/PHPjc/630805.html techarticle PHP Connection MySQL database class This is a simple and practical PHP connection MySQL database class, only do the data query, return the array set, get the new ID to get the record row, such as simple MySQL database ...

  • 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.