Multiple MySQL query with PHP


// Enter multiple query string
$query_str = "
-- Update table
UPDATE t SET id = id + 1;
-- Insert into table
INSERT INTO example (name, age) VALUES('John Doe', '23' );
";
// Explode string into separate queries
$query = explode(';',$query_str);
// Loop through exploded queries and execute
foreach($query as $index => $sql) {
$result = mysql_query($sql,$conn2) or userDisplayMessage(mysql_error().' '.__FILE__.':'.__LINE__);
}

Or, you can use mysqli (MySQL Improved extension), which has a mysqli_multi_query function.