我在az.pl上创建了一个数据库,我想使用在其他网站上运行良好的旧代码。我收到以下错误消息:
无法连接到mysql
这是我的密码:
$dbh = mysqli_connect("localhost","user","password", "db") or die ("could not connect to mysql");我也试过:
$c = mysql_connect("localhost", "user", "password");
mysql_select_db("db");
$result = mysql_query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = mysql_fetch_assoc($result);
echo htmlentities($row['_message']);都具有相同的结果,即错误消息。
我搜索过网络,但没有找到确切的问题。
发布于 2016-06-14 15:23:30
在调试连接问题时,请考虑遵循这些文档:
http://php.net/manual/en/function.mysqli-connect.php
<?php
$link = mysqli_connect("localhost", "user", "password", "db");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
// this will tell you why the connection failed
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>发布于 2016-06-15 18:37:01
我终于连接到数据库了。我所需要做的就是在以下代码中将isset更改为if:
if (!$_GET['pid']) {
$pageid = '1';
} else {
$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($link, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row["pagebody"];
}我使用MonkeyZeus代码连接到database.Thank you MonkeyZeus。
https://stackoverflow.com/questions/37815993
复制相似问题