Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
DROP TABLE IF EXISTS `foo`; CREATE TABLE foo ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL )

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $names = array_fill(0, 50000, 'foo'); $insert = 'INSERT INTO `foo` (firstname) VALUES '; foreach($names as $name) $insert.= '(\''.$name.'\'),'; $start = microtime(true); $pdo->query(trim($insert, ',')); $duration = microtime(true) - $start; echo 'Duration: '.$duration; echo PHP_EOL; $start = microtime(true); $insert = 'INSERT INTO `foo` (firstname) VALUES '; foreach($names as $name) $insert.= '(?),'; $stmt = $pdo->prepare(trim($insert, ',')); $stmt->execute($names); $duration = microtime(true) - $start; echo 'Duration: '.$duration;
Copy Clear