Questions tagged [multi-query]

Used for running multiple database queries/statements. Such as, queries separated by a semi-colon ';' in SQL. Or running multiple queries via separate requests.

SQL Example:

SELECT * FROM table1;
SELECT * FROM table2;

PHP/mysqli example1:

mysqli_multi_query(
    "SELECT * FROM table1;
     SELECT * FROM table2;"
);

PHP/mysqli example2:
This isn't really good practice, compared to the previous example, but this tag would still be fitting for a question with this type of code.

   mysqli_query("SELECT * FROM table1");
   mysqli_query("SELECT * FROM table2");

However, for PHP/mysqli, you should use mysqli-multi-query

84 questions
8
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
  • 392
  • 3
  • 9
6
votes
4 answers

mysql multi_query intermittently fails

function cpanel_populate_database($dbname) { // populate database $sql = file_get_contents(dirname(__FILE__) . '/PHP-Point-Of-Sale/database/database.sql'); $mysqli->multi_query($sql); $mysqli->close(); } The sql file is a…
Chris Muench
  • 17,444
  • 70
  • 209
  • 362
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
1 answer

Postgresql update 2 tables in one update statement

I have two different tabs with same field, like: host.enabled, service.enabled. How I can update his from 1 update statement? I tried: UPDATE hosts AS h, services AS s SET h.enabled=0, s.enabled=0 WHERE ctid IN ( SELECT hst.ctid FROM…
r1se
  • 67
  • 1
  • 1
  • 6
4
votes
0 answers

What am I missing? - PDO + transaction +multiple queries -

UPDATED - SEE THE ADDITION BELOW OK, straight away, I'm not a developer (maybe someday), I know almost nothing, classes, functions, methods, wrappers, foos, bars, and most of all OOP confuse the ever-loving-S out of me. That being said, I'm sure…
Michael Chad
  • 425
  • 4
  • 14
3
votes
1 answer

NHibernate second-level caching with multi-query

We're extensively using NHibernate multi-query functionality and experiencing strange behavior. Seems like NHibernate does not cache multiqueries and they always hit the database. We're using QueryOver, all queries are set to be cacheable, but when…
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
3
votes
2 answers

Which one is faster single big query or few small queries?

So I want to grab data from database, which method is faster, create several queries or one multi-query?
Giorgi Khmaladze
  • 113
  • 1
  • 2
  • 11
3
votes
1 answer

Mysqli multi_query not executing all queries

I'm updating or inserting multiple rows in database tables using Mysqli and multi_query. They work fine when I use them on my local MAMP server but break down when I take them online. On the remote server only three of the four queries are…
Jorgos
  • 123
  • 1
  • 11
2
votes
0 answers

nHibernate result from multiple SQL queries is empty

I'm grouping several SQL queries in a single multiquery. The queries are successfully executed. The result of multiQuery.List() is an ArrayList of ArrayLists. So far so good. However, the individual ArrayLists contain values of type {object[0]} or,…
Pieter
  • 3,339
  • 5
  • 30
  • 63
2
votes
1 answer

Running two SQL queries in PHP where the first statement creates a temporary table to be used by the second one

I want to run this long SQL query in PHP. CREATE TEMPORARY TABLE IF NOT EXISTS info AS ( SELECT warehouse.merchandise_id, SUM(warehouse.prod_quantity) AS qty FROM warehouse WHERE warehouse.merchandise_id IN (SELECT merchandise.id FROM…
stressed out
  • 522
  • 6
  • 24
2
votes
2 answers

NHibernate Multiquery for eager loading without joins

Is it possible to use a multiquery and have two hql queries returning two different sets of entities where one of the sets are used in the other and that the session "fixes" this via the first level cache? E.g. scenario (a dumb one and it could be…
Daniel
  • 8,133
  • 5
  • 36
  • 51
2
votes
1 answer

Can NHibernate QueryOver use MultiQuery?

session.CreateMultiQuery().Add(...) accepts IQuery, but IQueryOver does not appear to inherit from IQuery. Seems strange to me that I can't user QueryOver in a multi query?
Chris Haines
  • 6,445
  • 5
  • 49
  • 62
2
votes
2 answers

How to execute multiple MySql query at same time?

I want to update my data, I use this but it won't update my data, the id still empty. So, how I can execute multiple SQL queries at the same time? $mysqli = new mysqli("a", "a", "a", "a"); if (mysqli_connect_errno()) { printf("Connect failed:…
ade guntoro
  • 23
  • 1
  • 5
2
votes
2 answers

What is the Codeigniter equivilent to PHP multi_query

Whith PHP - I write a multi_query something like this: $MySQL_string .= "UPDATE `table` SET `name` = 'joe' WHERE `ID` = '1'"; $MySQL_string .= "UPDATE `table` SET `name` = 'Jane' WHERE `ID` = '2'"; if($DB->mysqli->multi_query($MySQL_string) ===…
user6749930
2
votes
2 answers

SELECT from 2 tables with different conditions

I've tried to get this for about 2 hours without success. Here is an example of what I need to do: Tables people: nameA score --------------------- someone1 24 someone2 24 someone3 24 someone4 23 someone5 …
C4d
  • 3,183
  • 4
  • 29
  • 50
1
2 3 4 5 6