- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在我的 php 代码中,我使用了一个 while 循环,如下所示。
<?php
$connection=mysqli_connect("localhost","root","","entries");
$query1="select * from jobs";
$query1exe=mysqli_query($connection,$query1);
$loopcount=0;
while($query1collector=mysqli_fetch_array($query1exe,MYSQLI_ASSOC)) {
$query2="insert into learning set name='new_1';
insert into learning set name='new_2';";
mysqli_multi_query($connection,$query2);
$loopcount++;
}
echo($loopcount);
?>
在这段代码中,我得到的输出为 104($loopcount),这意味着循环执行了 104 次。但是在名为 learning 的表中,我只有两个新条目 new_1 和 new_2。我预计有 208 个新条目(new_1 104 次和 new_2 104 次)。为什么我没有得到预期的结果。
我使用的是 PHP 版本 5.5.11
P.S 我想使用 mysqli_multi_query 本身,因为我需要同时执行几个查询。
这是我执行代码 3 次后我的学习表的样子
--------------------------------------------------------
slno | name | city | Phone
--------------------------------------------------------
1 | sandeep | NULL | NULL
-------------------------------------------------------
2 | new_1 | NULL | NULL
-------------------------------------------------------
3 | new_2 | NULL | NULL
-------------------------------------------------------
4 | new_1 | NULL | NULL
-------------------------------------------------------
5 | new_2 | NULL | NULL
------------------------------------------------------
6 | new_1 | NULL | NULL
------------------------------------------------------
7 | new_2 | NULL | NULL
-------------------------------------------------------
最佳答案
我看了官方文档here并找到了一条用户评论
if you mix $mysqli->multi_query and $mysqli->query, the latter(s) won't be executed!
仅使用 mysqli_query
,将您的多查询拆分为:
mysqli_query($connection,"insert into learning set name='new_1'");
mysqli_query($connection,"insert into learning set name='new_2'");
关于php - mysqli_multi_query 没有在 while 循环中多次执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33286946/
我正在执行 mysqli_multi_query(),其中包含 2 个查询: UPDATE Customers SET balance = balance + 15 WHERE ck
我正在通过 php 脚本更新 mysql 数据。我希望使用 mysqli_multi_query() 而不是 mysql_query。我要执行 N 个更新查询。请建议多查询是否有助于缩短执行时间。 A
我确信这个问题甚至在这个类(class)的创建者的博客上都没有问过。 从早上开始我就开始使用 bennettstone 的 php 数据库类.我试图将 MYSQLI_MULTI_QUERY 添加到此类
我在使用 mysqli_multi_query 时遇到问题。我可以多次INSERT INTO,但是一旦包含DELETE,所有后续查询都将不起作用。有趣的是,当将此查询粘贴到 phpMyAdmin SQ
只是想知道函数 mysqli_multi_query 是否仅连接到数据库一次或每个查询? 最佳答案 是的,因为它使用 $link 作为连接 ID http://php.net/manual/en/my
我在 mysqli_multi_query 的帮助下触发了以下查询。哪个执行正确但没有返回任何值。它返回空白。 mysqli_multi_query 有什么问题,或者是否有任何替代方法可以在 code
我正在对 PHP 执行 ajax 调用,它应该执行 2 个 SQL 查询。查询如下所示: $sql = "UPDATE customers SET customers_newsletter=1 WHE
$databases = array(); $path = '/Path/To/Directory'; $main_link = mysqli_connect('localhost', 'USERNA
使用 SO 上其他地方的示例来更好地捕获“隐藏”错误。虽然下面的代码将捕获并返回错误,但是否可以改进它以报告发生错误的查询? 使用下面的代码,输出是: Columns: 18 Error: You h
我正在尝试在下面的代码中使用 mysqli_multi_query 函数,但遇到了这个错误: 命令不同步;你现在不能运行这个命令 // add call stats to incoming nodes
我一直在尝试执行多个查询,因此我寻找了一种更好的方法来执行此操作,并且我在 php 中阅读了mysqli_multi_query。 我自己尝试了一下看看结果,但它一直给我错误。代码如下: $studi
我正在为我的 Android 应用程序创建 PHP API,该应用程序将用于扫描 QR 码。该 API 的一部分是检查扫描的代码是否有效并且可以在某个时刻进行扫描。 整个检查部分是MariaDB数据库
我以前从未使用过 mysqli_multi_query,它让我难以置信,我在网上找到的任何示例都无法帮助我准确地弄清楚我想要做什么。 这是我的代码: ">
我正在尝试提交 mysql 多重查询,但我不能... 当mysqli_multi_query“查询”有多个查询时无法提交。但是,当 mysqli_multi_query“查询”具有唯一查询时,它会被正
我正在运行多个 UPDATE SQL 查询: $queriesRun = mysqli_multi_query($connection, $queries); 现在,我如何循环遍历结果以了解哪些查询成
我在脚本的多个实例中使用了mysqli_multi_query()的程序版本。每次我使用这个函数时,它都会破坏我通过mysqli_connect()获得的连接。 这对我的 mysqli_insert_
我正在尝试使用 mysqli_multi_query() 从多个表中获取所有了解“Photoshop”的用户及其所有详细信息。我也得到了结果,但是也有一些不速之客以及正确的结果是空的。他们为什么会在这
我正在尝试删除我的主表“eleve”,同时删除主键在此的其他表。我尝试了所附代码,但出现错误: (Erreur de syntaxe pr�s de 'from bource where ID_BOU
我正在尝试做一个 mysqli_multi_query。由于某种原因,它不会工作。这是我到目前为止所做的: orderid 由ajax 给出。 最佳答案 查询必须用;分隔。 $sql = "INSE
我正在使用这段代码: $mysqli = new mysqli(...); $sql = file_get_contents("my_sql_file.sql"); $result = $mysqli
我是一名优秀的程序员,十分优秀!