Tags
PHP , MySQL
Asked 7 years ago
8 Feb 2017
Views 1395
jaydeep

jaydeep posted

how to run multiple query of MySQL in PHP ?


i want to run more than one MySQL query at once in PHP
example

$query="CREATE TABLE IF NOT EXISTS produce (id INTEGER PRIMARY KEY NOT NULL, name TEXT, description TEXT, image_url TEXT);INSERT INTO  `15`.`produce` (`id` ,`name` ,`description` ,`image_url`)VALUES ('1',  'test',  'test', NULL)";


so is there way to execute more than one MySQL query in php ?


Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

use PDO to run multiple query once in PHP

  $query="CREATE TABLE IF NOT EXISTS produce (id INTEGER PRIMARY KEY NOT NULL, name TEXT, description TEXT, image_url TEXT);INSERT INTO  `15`.`produce` (`id` ,`name` ,`description` ,`image_url`)VALUES ('1',  'test',  'test', NULL)";

$db = new PDO('mysql:host=localhost;dbname=test','admin','admin');
$db->exec($query);



exec function will run multiple query in PHP PDO
Rasi

Rasi
answered Nov 30 '-1 00:00

i also used PDO

you can do prepare and than run query by execute() function


$db = new PDO('mysql:host=localhost;dbname=15','admin','admin');
$stmt= $db->prepare($query);
 
    $stmt->execute();
Post Answer