Wamp,PHP MySQL - 连接错误
Wamp, PHP MySQL - Connecting error
我已经安装了 WAMP 服务器。现在我想使用 php 连接到 MySQL 数据库。我有一个问题,您需要获取用户名。
这是我使用的代码。来自 php.net http://php.net/manual/en/mysqli.quickstart.connections.php
<?php
$db_host = "localhost";
$db_username = "root";
$db_password = "password";
$db_name = "test";
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>
我收到以下错误:
Warning: mysqli::mysqli()
: in C:\wamp\www\Atletieker\dbconnect.php on line 7
Failed to connect to MySQL: (1045) Accès refusé pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI)
Warning: main()
: Couldn't fetch mysqli in C:\wamp\www\Atletieker\dbconnect.php on line 11
如何获取数据库的用户名?
试试这个...
$db_host = "127.0.0.1";
$db_username = "root";
$db_password = "";
$db_name = "test";
显然 $db_password
应该为空,如果您没有更改任何设置,默认密码应该为空。
我已经安装了 WAMP 服务器。现在我想使用 php 连接到 MySQL 数据库。我有一个问题,您需要获取用户名。 这是我使用的代码。来自 php.net http://php.net/manual/en/mysqli.quickstart.connections.php
<?php
$db_host = "localhost";
$db_username = "root";
$db_password = "password";
$db_name = "test";
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>
我收到以下错误:
Warning:
mysqli::mysqli()
: in C:\wamp\www\Atletieker\dbconnect.php on line 7 Failed to connect to MySQL: (1045) Accès refusé pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI)Warning:
main()
: Couldn't fetch mysqli in C:\wamp\www\Atletieker\dbconnect.php on line 11
如何获取数据库的用户名?
试试这个...
$db_host = "127.0.0.1";
$db_username = "root";
$db_password = "";
$db_name = "test";
显然 $db_password
应该为空,如果您没有更改任何设置,默认密码应该为空。