How To Process Multiple SQL Statements

PHP

How To Process Multiple SQL Statements

Sometimes you’ll find yourself needing to execute multiple statements at once. The normal mysql() class only allows for single statements, but the recent mysqli() offers this functionality.

To use it, follow this code example:

connect_error) {
echo “Error: Cannot connect to database”;
}

$sqlStatements =
“INSERT INTO tablename (name) values(‘John’);
INSERT INTO tablename (name) values(‘Sam’);”;

$batchSQLResult = $batchMysqli->multi_query($sqlStatements);

if($batchSQLResult == true) {
echo “Records inserted successfully”;
} else {
echo $batchMysqli->error;
}
?>

, , , ,

About Site Fixit!

Sam is a professional web designer and web developer. He has over 15 years of experience with web-related technologies, and loves making things work.

View all posts by Site Fixit!

No comments yet.

Leave a Reply