0

In order to run a query for database MySQL, we are using mysqli_query. Then, for running a query for database Oracle, we are using oci_execute.

When we wish to running multiple query for database MySQL, we are using mysqli_multi_query. Example as below:-

$mysqliconn = mysqliconn();         //mysqli connection
$sql = '
INSERT INTO TABLE VALUES();
INSERT INTO TABLE VALUES();
INSERT INTO TABLE VALUES();
INSERT INTO TABLE VALUES();
';
if(mysqli_multi_query($mysqliconn, $sql)) {
    echo 'Success';
}

My Question is if there anyone of you whom can come out with the most simplest solution to run multiple inserting values into the database table using one command execution.

Cid
  • 14,968
  • 4
  • 30
  • 45
Mimi
  • 3
  • 2
  • There's a similar question here: https://stackoverflow.com/questions/2449132/run-mysql-insert-query-multiple-times-insert-values-into-multiple-tables Would that help? – Hugo Sep 17 '19 at 09:16
  • @Hugo nope, the question is for Oracle. – Cid Sep 17 '19 at 09:20
  • Mimi in MySQL the way you've shown us isn't the best way to insert multiple entries. You should rather use `INSERT INTO table VALUES (), (), ();` – Cid Sep 17 '19 at 09:21
  • By the way, if your question is about Oracle, don't tag other RDBMS – Cid Sep 17 '19 at 09:25
  • @Hugo, my question is for Oracle. I just give an example in MySQL. Anyway, thanks for answering. – Mimi Sep 18 '19 at 02:36

2 Answers2

0

Oracle has an INSERT ALL statement for that. Otherwise you could just loop in your code and execute it n times.

Code Spirit
  • 3,992
  • 4
  • 23
  • 34
  • [`INSERT ALL`](https://www.javatpoint.com/oracle-insert-all) statement is really works. Thank you for giving me a new knowledge. – Mimi Sep 18 '19 at 07:53
-1
$sql = '
INSERT INTO TABLE abc VALUES(123,'xyz'),(456,'def'),(789,'qwe');
';

I suggest that using support library ^^

Phi Cuong
  • 1
  • 1