Home > Backend Development > PHP Tutorial > PHP connection mysql database class_PHP tutorial

PHP connection mysql database class_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:04:54
Original
808 people have browsed it

php connection mysql database class This is a simple and practical PHP class to connect to the MySQL database. It only performs data query, returns an array set, obtains a new ID, obtains a record row and other simple MySQL database connection codes.

php tutorial connection mysql tutorial database tutorial class
This is a simple and practical PHP class to connect to the MySQL database. It only performs data query, returns an array set, obtains a new ID, obtains a record row and other simple MySQL database connection codes.
*/

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);
}
}

//Call method

$db = new database;
$db->connect($dbhost, $dbuser, $dbpw, $dbname);
unset($dbhost, $dbuser, $dbpw, $dbname);


?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630805.htmlTechArticlephp connection mysql database class This is a simple and practical php connection mysql database class, only doing data query , return the array set, get the new id, get the record row and other simple mysql database...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template