gpt4 book ai didi

php - 使用Mamp和MySQL(PHP)“无法连接”

转载 作者:行者123 更新时间:2023-12-03 19:45:18 26 4
gpt4 key购买 nike

我正在尝试使用PHP访问我的MySQL数据库,但是我的页面不断返回错误“无法连接”。这是我的代码:

echo '<ul>';

$db_host = "localhost";
$db_user = "user";

$db_link = mysqli_connect($db_host, $db_user, $db_password, $db_name)
or die ("Unable to connect");

$sqlQuery = "SELECT u.user_name, m.message_text, m.time_stamp FROM users AS u INNER JOIN messages m ON u.user_id = m.user_id";

$result = mysqli_query($db_link, $sqlQuery);


if($result)
{
while ($row=mysqli_fetch_assoc($result))
{
echo "<li>" . $row['message_text'] . "<br>" . $row['user_name'] . "<br>" . $row['time_stamp'] . "</li>\n\t\t<hr>";
}
}
else
{
echo '<p>error displaying resultset</p>';
}

mysqli_close($db_link);
echo '</ul>';

最佳答案

<?php
$link = mysql_connect("localhost","root","") or die("Cannot connect to server");

$dbname="test";

mysql_select_db($dbname,$link) or die("Cannot connect to the database");

?>

关于php - 使用Mamp和MySQL(PHP)“无法连接”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22315144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com