mysqli multi_query
Posted: Tue Feb 01, 2011 3:03 pm
In order to avoid having to execute multiple queries with mysql_query I did some reading and found that with mysqli_multi_query you can execute multiple queries in one call (provided your sql syntax is correct). It works great. I can even iterate through each result. However, I found that on CREATE and DELETE statements it does not return any result. So how do I know if the table was deleted or created? Hear is the code.
First here is the sql code that I store in a file named install.sql:
Here is the php code:
The script runs and the table is created but I am unable to test the result in my php code. If anyone knows of any was to test if the table is deleted or created I would greatly appreciate any advise.
First here is the sql code that I store in a file named install.sql:
Code: Select all
DROP TABLE IF EXISTS `doc_classes`;
CREATE TABLE `doc_classes` (
`id` int(5) NOT NULL auto_increment,
`class` varchar(100) NOT NULL,
`package` varchar(100) NOT NULL,
`inherentance` varchar(255) NOT NULL,
`language_version` varchar(100) NOT NULL,
`runtime_version` varchar(100) NOT NULL,
`description` longtext NOT NULL,
PRIMARY KEY (`id`)
);
Code: Select all
<?php
$sql = new mysqli('localhost','root','root','DBName',8888);
$query = file_get_contents('install.sql');
$resource = $sql->multi_query($query);
if($resource){
do{
if($res = $sql->use_result()){
while($row = $res->fetch_object()){
print_r($row); echo "<br/><br/>";
}
}
}
while($sql->next_result());
}
?>