如何在PHP和MySQL中连接数据库? [英] How to connect database in PHP with MySQL?
本文介绍了如何在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#
这篇关于如何在PHP和MySQL中连接数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文