未捕获的错误:在布尔值中调用成员函数fetch_row()

时间:2018-07-24 18:58:15

标签: php mysql sql mysqli

在一个PHP文件中,我总共具有三个功能。我的第一个功能运行正常。第二和第三功能只是表名不同,否则一切都很好。当我运行第二个或第三个函数时,它给我以下错误

Uncaught Error: Call to a member function fetch_row() on boolean in 

最近两个功能的下一行都出现错误。

while($row = $result->fetch_row()) {

我已经从phpmyadmin测试了所有查询,并且查询正常,没有任何问题。

我的完整PHP文件如下所示

<?php
require_once("includes/conf.php");


function getAllNumbers() {
    global $conn;
    $sql = "SELECT number from number_list WHERE server=1";
    $result = $conn->query($sql);
    $data = array();
    if($result) {
        while($row = $result->fetch_row()) {
        array_push($data, $row[0]);
        }
    }
    $response["data"] = $data;
    return $response;
}

function getNewNumbers() {
    global $conn;
    $sql = "SELECT number, id from new_numbers WHERE server = 1";
    $result = $conn->query($sql);
    $newData = array();
    if($result) {
        while($row = $result->fetch_row()) {
        array_push($newData, $row[0]);
        $id = $row[1];
        $delete = "DELETE number from new_numbers WHERE id = $id";
        $result = $conn->query($delete);

        }
    }
    $response["newData"] = $newData;
    return $response;
}

function getDeleteNumbers() {
    global $conn;
    $sql = "SELECT number, id from delete_numbers WHERE server = 1";
    $result = $conn->query($sql);
    $deleteData = array();
    if($result) {
        while($row = $result->fetch_row()) {
        array_push($deleteData, $row[0]);
        $id = $row[1];
        $delete = "DELETE number from delete_numbers WHERE id = $id";
        $result = $conn->query($delete);

        }
    }
    $response["deleteData"] = $deleteData;
    return $response;
}

?>

表number_list

id  int(11) NO  PRI NULL    auto_increment  
name    varchar(50) NO      NULL        
number  varchar(50) NO      NULL        
server  int(10) NO      0       
status  int(1)  NO      -1      
last_act    timestamp   NO      CURRENT_TIMESTAMP       
user_id int(11) NO  MUL NULL        
created_at  timestamp   NO      CURRENT_TIMESTAMP       
disable int(11) NO      0       
notify  int(1)  NO      1       
fcm varchar(500)    NO      NULL

表new_numbers

id  int(11) NO  PRI NULL    auto_increment  
number  varchar(50) NO      NULL        
server  int(10) NO      0   

表delete_numbers

id  int(11) NO  PRI NULL    auto_increment  
number  varchar(50) NO      NULL        
server  int(10) NO      0   

让我知道是否有人可以帮助我解决问题。非常感谢。

0 个答案:

没有答案