PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
DROP TABLE IF EXISTS `foo`; CREATE TABLE foo ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, address VARCHAR(30) NOT NULL, tel VARCHAR(30) NOT NULL, size VARCHAR(30) NOT NULL, weight VARCHAR(30) NOT NULL ) ;
Copy Clear
Copy Format Clear
<?php $names = array_fill(0, 100000, array('foo', 'ln', 'ad', 'tel', 'sz', 'wgh')); $start = microtime(true); $insert = 'INSERT INTO `foo` (firstname, lastname, address, tel, size, weight) VALUES '; foreach ($names as $name) $insert .= '(\''.implode('\', \'', $name).'\'),'; $pdo->query(trim($insert, ',')); $duration = microtime(true) - $start; echo 'Duration: '.$duration, " ", memory_get_peak_usage(); echo PHP_EOL; $start = microtime(true); $insert = 'INSERT INTO `foo` (firstname, lastname, address, tel, size, weight) VALUES '; foreach($names as $name) $insert.= '(?,?,?,?,?,?),'; $names = array_merge(...$names); echo memory_get_usage(); $stmt = $pdo->prepare(trim($insert, ',')); $stmt->execute($names); $duration = microtime(true) - $start; echo 'Duration: '.$duration;
Show:  
Copy Clear