-3

我正在尝试使用我网站上的 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.

问题是什么,我在哪里犯了错误?

4

2 回答 2

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 并且没有提供正确的参数会引发错误。

于 2014-09-06T05:55:46.740 回答
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');
于 2014-09-06T05:59:21.283 回答