Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 致命错误:调用未定义的方法mysqli_result::rowCount()_Php_Mysqli_Count_Fetch - Fatal编程技术网

Php 致命错误:调用未定义的方法mysqli_result::rowCount()

Php 致命错误:调用未定义的方法mysqli_result::rowCount(),php,mysqli,count,fetch,Php,Mysqli,Count,Fetch,我在从MYSQL切换到MYSQLi时遇到问题。这些代码在MYSQL中运行良好,但当我更改与MYSQLi的连接时,我在获取查询时收到了如上所述的错误。如何使用mysqli函数获取查询 代码: 使用num_行 阅读 所以最后的答案是 function getItems($id = null) { if(isset($_GET['id'])) { $query = $this->link->query("SELECT * FROM items WHERE i

我在从MYSQL切换到MYSQLi时遇到问题。这些代码在MYSQL中运行良好,但当我更改与MYSQLi的连接时,我在获取查询时收到了如上所述的错误。如何使用mysqli函数获取查询

代码:

使用num_行

阅读

所以最后的答案是

function getItems($id = null)
{
    if(isset($_GET['id']))
    {
        $query = $this->link->query("SELECT * FROM items WHERE id = '$id'");
    }
    else
    {
        $query = $this->link->query("SELECT * FROM items");
    }
    $rowCount = $query->num_rows;//change here
    if($rowCount >= 1)
    {
        $result = $query->fetchAll();
    }
    else
    {
        $result = 0;
    }
    return $result;
}
编辑01

使用而不是fetchAll

所以,回答这个世界

    if($rowCount >= 1)
    {
        $result = mysqli_fetch_all($query,MYSQLI_ASSOC);
    }
使用num_行

阅读

所以最后的答案是

function getItems($id = null)
{
    if(isset($_GET['id']))
    {
        $query = $this->link->query("SELECT * FROM items WHERE id = '$id'");
    }
    else
    {
        $query = $this->link->query("SELECT * FROM items");
    }
    $rowCount = $query->num_rows;//change here
    if($rowCount >= 1)
    {
        $result = $query->fetchAll();
    }
    else
    {
        $result = 0;
    }
    return $result;
}
编辑01

使用而不是fetchAll

所以,回答这个世界

    if($rowCount >= 1)
    {
        $result = mysqli_fetch_all($query,MYSQLI_ASSOC);
    }

您可以使用num_rows来计算数据库中的行数,并且可以像这样直接调用连接:-

//for connection

$con = mysqli_connect("localhost", "root", "", "ajax_rating");
if(!$con)
{
echo "connection error";
}


//query
function getItems($id = null)
 {
if(isset($_GET['id']))
{
    $query = mysqli_query($con,"SELECT * FROM items WHERE id = '$id'");
}
else
{
    $query = mysqli_query($con,"SELECT * FROM items");
}
if (mysqli_num_rows($query) > 0)//change here
    {
    while($row = mysqli_fetch_assoc($query))
     {
       $result=$row;
     }

}
else
{
    $result = 0;
}
return $result;
}

您可以使用num_rows来计算数据库中的行数,并且可以像这样直接调用连接:-

//for connection

$con = mysqli_connect("localhost", "root", "", "ajax_rating");
if(!$con)
{
echo "connection error";
}


//query
function getItems($id = null)
 {
if(isset($_GET['id']))
{
    $query = mysqli_query($con,"SELECT * FROM items WHERE id = '$id'");
}
else
{
    $query = mysqli_query($con,"SELECT * FROM items");
}
if (mysqli_num_rows($query) > 0)//change here
    {
    while($row = mysqli_fetch_assoc($query))
     {
       $result=$row;
     }

}
else
{
    $result = 0;
}
return $result;
}

嗯,我之前试过,但它让我调用了未定义的方法mysqli_result::fetchAll,我已经研究过了,似乎我需要某种本机驱动程序?该方法的名称发生了更改。它现在被称为mysqli_result::fetch_all。resultset对象上的所有方法都记录在这里:嗯,我之前尝试过,但它调用了未定义的方法mysqli_result::fetchAll,我已经研究过了,似乎我需要某种本机驱动程序?该方法的名称发生了更改。它现在被称为mysqli_result::fetch_all。resultset对象上的所有方法都记录在此处: