php - 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....
解决方案
请试试:
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 手册。
推荐阅读
- python - 使用熊猫在具有重复日期的csv文件中添加缺少的日期
- ios - 如何在 iOS 中从呼叫方的呼叫中获取视频窗口?
- nativescript - NativeScript-Angular:nsRouterLink 在 Android 上打开组件,但在 iOS 上不打开
- mongodb - MongoCollection.find() 搜索两次?
- google-apps-script - 无法将 Google 编辑器插件发布到 G Suite Marketplace
- docusignapi - DocuSign API - 我想要用于报告的 API
- c# - 允许视图中的可空模型
- flutter - 如何在颤动中对齐定位小部件内的文本?
- spring - $expand 无限制地获取所有数据
- jquery - 在 laravel 中使用 jquery 在 div 中显示响应 json 消息