douhuo1738 2013-07-16 21:27
浏览 68
已采纳

PHP MySQL没有从数据库中获取任何东西

Trying to get all the users from my database, yet when I do so, the query fails.

Attempting to do so with

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

Where in PHPMyAdmin the database has a few records in the table login. I checked if the connection is connected, its connected.

Is there any reason this wouldn't work?

Here is a examplepage, you can try logging in with Username and Password.

EDIT: From the example page, here is the code used to test:

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 />";
}

EDIT 2: Here is a screenshot of the table existing, and the data existing: Something

  • 写回答

3条回答 默认 最新

  • dongliao8069 2013-07-19 23:28
    关注

    I use this

    $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 />";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试