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(60) NOT NULL, lastname VARCHAR(60) NOT NULL, address VARCHAR(60) DEFAULT NULL, tel VARCHAR(60) NOT NULL, size VARCHAR(60) NOT NULL, weight VARCHAR(60) NOT NULL ) ;
Copy Clear
Copy Format Clear
<?php function implode_flds(array $row){ $str = ''; $del = ''; foreach ($row as $f) { if (is_null($f) or strtoupper($f) == 'NULL'){ $f = 'NULL'; } elseif (is_string($f)){ $f = '\'' . $f . '\''; } $str .= $del.$f; $del = ','; } return $str; } $names = array_fill(0, 60000, array('foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoo', 'lnlnlnlnlnlnlnlnlnlnlnlnfoofoofoofoofoofoofoofoofoofoo', null, 'teltelteltelteltelteltelteltelteltelfoofoofoofoofoofoofoofoofoofoo', 'szszszszszszszszszszszszszszszszfoofoofoofoofoofoofoofoofoofoo', 'wghwghwghwghwghwghwghwwghwghwghwghwghwghwghwfoofoofoofoofoofoofoofoofoofoo')); $start = microtime(true); $insert = 'INSERT INTO `foo` (firstname, lastname, address, tel, size, weight) VALUES '; foreach ($names as $name) { $insert .= '('.implode_flds($name).'),'; } $pdo->query(trim($insert, ',')); $duration = microtime(true) - $start; echo 'Duration: '.$duration; 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); $stmt = $pdo->prepare(trim($insert, ',')); $stmt->execute($names); $duration = microtime(true) - $start; echo 'Duration: '.$duration;
Show:  
Copy Clear