PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table t ( a int, b int, c int );
Copy Clear
Copy Format Clear
<?php $data = [ ['a' => 1, 'b' => 2, 'c' => 3], ['a' => 1, 'b' => 2, 'c' => 3], ['a' => 1, 'b' => 2, 'c' => 3], ['a' => 1, 'b' => 2, 'c' => 3], ['a' => 1, 'b' => 2, 'c' => 3] ]; $query="INSERT INTO t (a, b, c) VALUES " . implode( ', ', array_fill( 0, count($data), '(' . implode (', ', array_fill(0, count($data[0]), '?')) . ')' ) ); echo $query; $values = array_reduce( $data, function($ac, $el) { return array_merge($ac, array_values($el)); }, [] ); var_export($values); $q=$pdo->prepare($query); $q->execute($values); // test $query = "SELECT * FROM t;"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); var_export($rows);
Show:  
Copy Clear