When and How to use Multiple MySQL Queries with PHP (PDO)

Tags: php mysql pdo

What are the benefits of using multiple MySQL queries in a statement, other than to minimize code.

How do you execute, retrieve, and display the results of multiple MySQL queries sent in one statement using PHP (and preferably PDO).

By : GeekJock


Multiple queries on the same call are especially beneficial when you need to work with session variables and temporary tables:

select somecol, @somevar := group_concat( distinct somecol2 separator '|')
from sometbl
    somecol LIKE "fueh"
group by somecol;

select somecol2
from  sometbl
    somecol LIKE "nyan"
    vc_wp regexp concat( '(', @somevar, ')' )
order by somecol;

I was doing some research tonight and stumbled across this thread. None of the answers above provide a viable solution to this simple problem.

Using the OO Approach, you can perform multiple query statements in a single connection by using the multi_query() method.


Queries should be well-formed and separated by semicolons -> ;

see The PHP manual for more details on how to handle SELECT data

By : BizLab

To be specific, TDateTime isn't object, it's just an alias for double.

By : Harriv

This video can help you solving your question :)
By: admin