Questions tagged [mysqli-multi-query]

Use this tag in case of multi-query execution in mysqli. mysqli_multi_query() executes one or multiple queries which are concatenated by a semicolon and returns TRUE on success or FALSE on failures.

mysqli_multi_query() executes one or multiple queries which are concatenated by a semicolon and returns TRUE on success or FALSE on failures. This can be performed either as procedural style or OOP style(see usage section).

Usage

Object oriented style

bool mysqli::multi_query ( string $query )

Procedural style

bool mysqli_multi_query ( mysqli $link , string $query )
  • bool is the return value type and depends on the passed $variable.
  • mysqli:: refers to the object initialised using stmt_init() or mysqli_prepare() call.
  • $query is the query, as a string. Data inside the query should be properly escaped.

Miscellaneous

  • mysqli_query() - Performs a query on the database
  • mysqli_use_result() - Initiate a result set retrieval
  • mysqli_store_result() - Transfers a result set from the last query
  • mysqli_next_result() - Prepare next result from multi_query
  • mysqli_more_results() - Check if there are any more query results from a multi query

Related tag

178 questions
11
votes
3 answers

Strict Standards: mysqli_next_result() error with mysqli_multi_query

I have tried using multi_query but I keep getting a strict Standards message popping up. $querystring = "INSERT INTO responses VALUES('1', '2', '3', '4'); INSERT INTO responses VALUES('1', '2', '3', '4')"; if (mysqli_multi_query($db,…
Phil
  • 309
  • 1
  • 3
  • 9
10
votes
6 answers

Cannot figure out how to run a mysqli_multi_query and use the results from the last query

I've never used mysqli_multi_query before and it's boggling my brain, any examples I find on the net aren't helping me to figure out exactly what it is I want to do. Here is my code:
Harry Weinert
  • 141
  • 1
  • 1
  • 6
9
votes
3 answers

"Commands out of sync; you can't run this command now" - Caused by mysqli::multi_query

I am running multiple deletes through mysqli::multi_query and it is messing up the next query in line. The following error is being thrown. Error - SQLSTATE HY000. Sql error: Commands out of sync; you can't run this command now Do I need to…
andrew
  • 4,758
  • 9
  • 40
  • 56
8
votes
2 answers

mysqli_multi_query - Commands out of sync; you can't run this command now

I have several query strings which I want to execute at once using "mysqli_multi_query". This works. When I insert a query again to check each item in joined tables using "mysqli_query" it doesn't return any result nor any error from PHP. When I run…
Edison
  • 243
  • 2
  • 10
8
votes
2 answers

Speed/best practice flushing mysqli_multi_query()

I cringed when Sebastien stated he was disconnecting & reconnecting between each use of mysqli_multi_query() @ Can mysqli_multi_query do UPDATE statements? because it just didn't seem like best practice. However, Craig @ mysqli multi_query followed…
mickmackusa
  • 33,121
  • 11
  • 58
  • 86
7
votes
3 answers

Why does multi_query not work when I use transactions?

Here is an example. $mysqli = new mysqli("localhost", "root", "123", "temp"); $mysqli->begin_transaction(); $sql1 = "insert into test (Name) values ('pratik5');"; $sql1 .= "insert into test (Name) values ('pratik6');"; $test =…
Pratik Solanki
  • 384
  • 3
  • 9
7
votes
1 answer

How to use async Mysql query with PHP PDO

The Mysqlnd driver PHP 5.6 have opportunity to use a Async queries http://php.net/manual/en/mysqli.reap-async-query.php How to use Async queries with PDO? it is not work, code (PHP asynchronous mysql-query): $dbConnectionOne = new \PDO($cnn0,…
7
votes
2 answers

What Does mysqli_store_result() Actually Do?

I want to understand that What mysqli_store_result Actually does? When I visited the PHP Manual of mysqli_store_result, I found the definiton mysqli_store_result — Transfers a result set from the last query The Question is Where it transfers the…
Munib
  • 2,995
  • 7
  • 24
  • 35
6
votes
3 answers

PHP/mysqli - prepared statement (in a loop) or multi_query

I've just moved on from using mysql to mysqli extension in PHP. I've come across two ways of doing the same thing (multiple update queries), what are the pros/cons of each? Should I be using one or the other or something else entirely? Prepared…
Dan
  • 347
  • 1
  • 3
  • 8
6
votes
1 answer

Why I am getting the Error "Commands out of sync; you can't run this command now"

The Documentation of the Error Mentioned in the Title Says If you get Commands out of sync; you can't run this command now in your client code, you are calling client functions in the wrong order. This can happen, for example, if you are using…
Munib
  • 2,995
  • 7
  • 24
  • 35
6
votes
2 answers

Letting a PHP multi Query continue if errors occur

I got this Code: // Some starting variables $test = new mysqli("localhost","root","","testdatabase"); $Query = array(); $Query[] = "SELECT 'wos' FROM items WHERE itemID = 3"; $Query[] = "SELECT 'wos' FROM items WHERE itemID"; $Query[] = "SELECT…
user1648409
5
votes
2 answers

Does mysqli_multi_query send the whole SQL to the database in a single trip?

I am seriously doubting mysqli's multi-queries are truly multi-queries in the sense that the total trip made to the database from the web server is only 1. If we call a 5-statement multi-query, we have to do multi_query() once and next_result() 4…
Pacerier
  • 76,400
  • 86
  • 326
  • 602
5
votes
3 answers

Multiple MySql WHERE Between Clauses

Newbie MySql programmer thanks for the patience. Im trying to track an Id number in a table where 3 different conditions are met this is what Iv got however the query dosent return any results where there are clearly matches in the table.…
Christopher
  • 8,739
  • 8
  • 28
  • 37
5
votes
1 answer

Why does mysqli::multi_query stop after a certain amount of rows?

I'm attempting to run a fairly large amount of updates/inserts on a table using multi_query. There are ~14,000 queries total, but the function only executes ~480, then it stops without errors and PHP continues the script beyond the snip…
Erik
  • 192
  • 1
  • 11
4
votes
3 answers

Trying to understand php mysqli multi_query

I have a function that is designed to copy a product with all attributes with help of sql querys. My problem is to return new_product_id to php after completion. If i run sql script in phpmyadmin all is working. If i run sql script with php function…
fobaey
  • 51
  • 2
1
2 3
11 12