Class classdb{
var $localhost = ' 127.0.0.1 ';
var $user = ' root ';
var $pass = ' 123456 ';
var $links = ';
var $charset = ' GBK ';
Function Connect ()
{
try{
if (' p ' = = $this->links)
{
$this->conn = mysql_pconnect ($this->localhost, $this->user, $this->pass) or Die (Mysql_error ());
}
Else
{
$this->conn = mysql_connect ($this->locahost, $this->user, $this->pass) or Die (Mysql_error ());
}
mysql_select_db ($this->db, $this->conn);
mysql_query ("Set Names ' $this->charset '");
}
catch (Exception $e)
{
Echo ' Database connection failed, ';
Exit
}
}
}
Code Instance Two
mysql_connect ("localhost", "root", "1981427")//Select database before you need to connect to the database server
Or Die ("Database server Connection Failed");
mysql_select_db ("test")//Select Database MyDB
Or Die ("database does not exist");
Starter Database Connection Two
Mysql_connect ("$host", "$user", "$password") or Die ("Unable to connect to the MySQL database server!") ");
$db = mysql_select_db ("$dbname") or Die ("Unable to connect to the database!") ");
/*
Description
Mysql_connect (Host: port, username, password); the MySQL server connected to the batch defaults to 3306 ports, the connection is closed automatically when the script is finished, or it can be closed in advance with Mysql_close
mysql_create_db (database name); Select default Database
mysql_query (SQL statement, connection number), querying the specified database
This article is original in www.111cn.net reprint annotated provenance, otherwise must investigate
*/