略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: mysqli::reap_async_query

2024-12-21

mysqli::reap_async_query

mysqli_reap_async_query

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

mysqli::reap_async_query -- mysqli_reap_async_query获取异步查询的结果

说明

面向对象风格

public mysqli::reap_async_query(): mysqli_result

过程化风格

mysqli_reap_async_query(mysqli $link): mysqli_result

获取异步查询的结果, 仅可用于 mysqlnd。。

参数

mysql

仅以过程化样式:由mysqli_connect()mysqli_init() 返回的 mysqli 对象。

返回值

如果成功则返回 mysqli_result,否则返回 false

参见

add a noteadd a note

User Contributed Notes 1 note

up
5
eric dot caron at gmail dot com
12 years ago
Keep in mind that mysqli::reap_async_query only returns mysqli_result on queries like SELECT. For queries where you may be interested in things like affected_rows or insert_id, you can't work off of the result of mysqli::reap_async_query as the example in mysqli::poll leads you to believe. For INSERT/UPDATE/DELETE queries, the data corresponding to the query can be accessed through the associated key to the first array in the mysqli::poll function.

So instead of
<?php
   
foreach ($links as $link) {
        if (
$result = $link->reap_async_query()) {
           
print_r($result->fetch_row());
           
mysqli_free_result($result);
           
$processed++;
        }
    }
?>

The data is accessible via:
<?php
   
foreach ($links as $link) {
        if (
$result = $link->reap_async_query()) {
           
//This works for SELECT
           
if(is_object($result)){
               
print_r($result->fetch_row());
               
mysqli_free_result($result);
            }
           
//This works for INSERT/UPDATE/DELETE
           
else {
               
print_r($link);
            }
           
$processed++;
        }
    }
?>

官方地址:https://www.php.net/manual/en/mysqli.reap-async-query.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3