0

试图从我的数据库中获取所有用户,但是当我这样做时,查询失败。

试图这样做

 $userNames = mysqli_query($con, "SELECT * FROM Login");

在 PHPMyAdmin 中,数据库在表登录中有几条记录。我检查了连接是否已连接,它已连接。

有什么理由这行不通吗?

这是一个示例页面,您可以尝试使用用户名和密码登录。

编辑:从示例页面,这里是用于测试的代码:

if (mysqli_connect_errno($con)) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error() . "<br />";
} else {
    echo "Connected to MySQL!<br />";
}
if(mysqli_query($con, "SELECT * FROM Login")){
    echo "Query good!<br />";
} else {
    echo "Query bad!<br />";
}

编辑 2:这是现有表格和现有数据的屏幕截图: 某物

4

3 回答 3

1

我用这个

$con = StartDatabase("localhost", "username", "password", "mydatabase");

function StartDatabase($dblocation, $dbuser, $dbpasswd, $dbname){
 $link = mysqli_connect($dblocation, $dbuser, $dbpasswd, $dbname);
  if (!$link) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
        . mysqli_connect_error());
  }
 return $link;
}

if(mysqli_query($con, "SELECT * FROM Login")){
    echo "Query good!<br />";
} else {
    echo "Query bad!<br />";
}
于 2013-07-19T23:28:16.847 回答
0

尝试将此添加到查询的 else 以获得错误输出:

echo "Error code ({$con->errno}): {$con->error}";
于 2013-07-16T22:00:28.530 回答
0

试试这样:

$con = new mysqli("pdb1.awardspace.com", "*******", "****", "*******");

$query = "SELECT * FROM Login";

if ( !$con->query($query) ) {
    echo "Query bad!<br />";
    echo mysqli_connect_error() . "<br />";
    echo "Error code ({$sql->errno}): {$sql->error}";
} else {
    echo "Query good!<br />";
}
$con->close();
于 2013-07-16T22:23:34.073 回答