如何在PHP和MySQL中连接数据库?
问题描述:
这是我的代码.它无法连接到数据库.
Here is my code. It cannot connect to database.
class connect{
// Check MySQL
function chkmys(){
if (mysql_errno()>0) die("MySQL error ".mysql_errno()." : ".mysql_error());
}
// Open a connection
function open(){
$hst = "127.0.0.1";
$usr = "root";
$pwd = ""; //KsfHMyDb#
$dbs = "mine_db";
$vsr = "D:\wamp\bin\mysql\mysql5.0.51b\data";
if(file_exists($vsr)) {
$cnx = mysql_connect($hst,$usr,$pwd);
/* if (!$cnx) die('Failed to open connection to MySQL server');*/
mysql_select_db($dbs,$cnx);
connect::chkmys();
return $cnx;
}
}
// Close a connection
function close($cnx){
mysql_close($cnx);
}
}
答
hst = " ;
hst = "127.0.0.1";
usr = " ;
usr = "root";
pwd = " ; // KsfHMyDb#
pwd = ""; //KsfHMyDb#