gpt4 book ai didi

php - 我无法连接到mysql

转载 作者:行者123 更新时间:2023-11-29 20:53:36 26 4
gpt4 key购买 nike

我已经在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']);


两者具有相同的结果,错误消息。

我已经在网上搜索过,但没有找到确切的问题。

最佳答案

在调试连接问题时,请考虑遵循以下文档:

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);
?>

关于php - 我无法连接到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37815993/

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