0

I have a procedural php script which employs a mysqli_multi_query statement into which I must now add a SELECT statement. After many attempts, I have to admit that this appears to be a bit outside my ken. I need some help with the grammar… or perhaps the procedure:

The code has SELECTed nothing to this point, and therefore has never needed its results to be queried. How would I retrieve a single result?

Here is my script. I have omitted the details of the other queries.

INSERT INTO table1 ...;
SELECT LAST_INSERT_ID() INTO @varX;
INSERT INTO table2 ...;
INSERT INTO table3 ...;
INSERT INTO table4 ...;
DELETE FROM table0;
SELECT `id` FROM subscribers WHERE `column` = @varX;

I want that last statement's id from SELECT id FROM patronsSubscr WHERE column = @varX;

They are run from php using this function:

$result = mysqli_multi_query($connection,$sql)
    or die("Error.");

I have been trying to use variations of this, with no luck:

while($resultNexts = mysqli_next_result($result)){
    // output
}

Any help would be appreciated. Please let me know if I can provide any more information.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Parapluie
  • 714
  • 1
  • 7
  • 22
  • 1
    by omitting the details of the queries you make it harder to answer but one method you could possibly employ would be to use a `stored procedure` - if the queries are run frequently with no deviation but alternative parameters that is. Create a SP on the db that does all the tasks and then as the final query does the select – Professor Abronsius May 07 '19 at 18:32
  • I try to figure out what you mean by retrieve single result . Php will get confused if all queries are in one jar . If you want to retrieve just select statement then run it as single query.in such case I would use loop on all the queries and it will be much easy than the above method. – Creative87 May 07 '19 at 18:39
  • My general recommendation about `mysqli_multi_query` is DON'T USE IT. It just makes things more complicated, and provides little benefit. – Barmar May 07 '19 at 18:53
  • @Barmar I've got that feeling already. Looking at that duplicate, I think it's pretty dirty. But I think that it will do the work until I get time to rebuild the whole script. Thanks, everyone. – Parapluie May 07 '19 at 19:21

0 Answers0