Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Data Tables in PHP/MySQL?

Tags:

php

mysql

dataset

In asp.net, you can retrieve MULTIPLE datatables from a single call to the database. Can you do the same thing in php?

Example:

$sql ="select * from t1; select * from t2;";
$result = SomeQueryFunc($sql);
print_r($result[0]); // dump results for t1
print_r($result[1]); // dump results for t2

Can you do something like this?

like image 985
John Avatar asked Dec 03 '25 20:12

John


1 Answers

This is called "multi-query." The mysql extension in PHP does not have any means to enable multi-query. The mysqli extension does allow you to use multi-query, but only through the multi_query() method. See http://php.net/manual/en/mysqli.multi-query.php

Using multi-query is not recommended, because it can increase the potential damage caused by SQL injection attacks. If you use multi-query, you should use rigorous code inspection habits to avoid SQL injection vulnerability.

like image 54
Bill Karwin Avatar answered Dec 06 '25 09:12

Bill Karwin