这是我的密码。
<?php
$server = "localhost";
$uname = "replace it with anything";
$pswd = "";
$conn = mysqli_connect($server, $uname, $pswd);
if(!$conn){
die('Caught');
}
else{
die('Connected');
}
?>无论我在mysqli_connect()中传递了什么作为用户名。它总是返回true。在错误密码的情况下,它显示一个访问被拒绝的错误,但是我不知道为什么,不管我在用户名中输入了什么,它总是返回true。
发布于 2017-05-17 15:53:42
它不返回布尔值,而是返回表示连接的对象。然后,您可以检查对象的连接性。从手册中:
<?php
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
/*
* This is the "official" OO way to do it,
* BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
*/
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}发布于 2017-05-17 16:13:45
试一试
<?php
$mysqli = new mysqli("host", "username", "password", "database") or die($mysqli->error());
if ($mysqli->connect_errno) {
echo "error";
exit();
}
?>https://stackoverflow.com/questions/44029563
复制相似问题