首页 > 解决方案 > Trying to get value from PHP multi_query

问题描述

I'm stuck on this problem for a while now and looking for helpful suggestions.

$resultset = $connection->multi_query($sql);

pseudo:

IF $resultset > 0 (--> if the sql query returned at least one result) {
 // do something
}

now the problem is with the pseudo part, i have tried to the follows:

if($resultset > 0) // takes no effect
if($resultset->num_rows > 0) // Notice: Trying to get property of non-object

I have to use multi_query so mysqli_query/mysqli_fetch_array is not a solution

thanks for the hints....

标签: phpmysqli

解决方案


请试试:

if($connection->multi_query($sql))
{
    //sample query taken from php manual, see link below
    do {
        /* store first result set */
        if ($result = $connection->store_result()) {
            while ($row = $result->fetch_row()) {
                printf("%s\n", $row[0]);
            }
            $result->free();
        }
        /* print divider */
        if ($connection->more_results()) {
            printf("-----------------\n");
        }
    } while ($connection->next_result());

}
else
{
    //handle error
    echo mysqli_error ( $connection );
}

如果您查看多查询的文档(此处),您将看到该函数返回一个boolean.

源代码也取自php 手册


推荐阅读