php脚本无法在我的网站上运行

时间:2014-09-06 05:52:09

标签: php web-development-server

我试图使用我网站上的php连接我的数据库。我使用以下代码进行连接,

$db_host="10.12.209.82";
$db_username="username";
$db_pass="pass";
$db_name="DBName";
mysql_connect($db_host,$db_username,$db_pass) or die("Could not connect to my sql");
mysql_connect($db_name) or die("No Database");

但是当我在我的网站上运行该文件时,它显示以下错误...

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

问题是什么?我犯了错误?

2 个答案:

答案 0 :(得分:1)

应该是(mysql_select_db):
 

$db_host="localhost";
$db_username="root";
$db_pass="302010asd";
$db_name="mvnodb";
mysql_connect($db_host, $db_username, $db_pass) or die("Could not connect to my sql");
mysql_select_db($db_name) or die("No Database");

再次调用mysql_connect并且没有正确提供参数会引发错误。

答案 1 :(得分:1)

不要使用mysql已经弃用了MySQLI或PDO而不是..

使用MySQLI,您只需执行此操作即可连接到服务器。

define('HOST','10.12.209.82');
define('USER','username');
define('PASSWORD','password');
define('Database','dbname');

$dbh = mysqli_connect(HOST,USER,PASSWORD,DATABASE) or die('Cannot connect to the server');