dshmkgq558192365 2015-12-24 06:44
浏览 268
已采纳

错误:警告:mysqli_fetch_array()要求参数1为mysqli_result,第15行/var/www/html/data.php中给出布尔值[复制]

I am trying to select data from a MySQL table to show data's in my c# datagridview, but I get one of the following error messages:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /var/www/html/data.php on line 15

This is my PHP code:

<?php 

$servername = "********";
$username = "root";
$password = "pws";
$dbname = "dbs";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "SELECT userid,password,first_name,last_name,role,active FROM aster_users";
$result = mysql_query($sql);
while($row = mysqli_fetch_array($result)) 
    {
        $userid=$row['userid'];
        $password=$row['password'];
        $first_name=$row['first_name'];
        $last_name=$row['last_name'];
        $role=$row['role'];
        $active=$row['active'];
    }
$conn->close();
?>

Help me,

</div>
  • 写回答

3条回答 默认 最新

  • douxian9706 2015-12-24 06:49
    关注

    You cannot mix the mysql and mysqli. For database queries please use mysqli_query($conn,$query). http://php.net/manual/en/mysqli.query.php

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    $sql = "SELECT userid,password,first_name,last_name,role,active FROM aster_users";
    $result = mysqli_query($conn,$sql); // NOTICE HOW THIS IS MYSQLI QUERY. NOT MYSQL
    while($row = mysqli_fetch_array($result)) 
        {
            $userid=$row['userid'];
            $password=$row['password'];
            $first_name=$row['first_name'];
            $last_name=$row['last_name'];
            $role=$row['role'];
            $active=$row['active'];
        }
    mysqli_close($conn); //Use Procedural Code Here. not $conn->close();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料