query('DELETE FROM tt'); } function test_non_prep($con) { delete($con); $t1 = microtime(true); for($i = 0; $i < N; $i++) { $s = 'Some text bla bla bla'; $stmt = $con->query("INSERT INTO tt VALUES ($i, '$s')"); } $t2 = microtime(true); $dt = (int)(($t2 - $t1) * 1000); echo "Non prepared: $dt\r\n"; } function test_prep_sing($con) { delete($con); $t1 = microtime(true); for($i = 0; $i < N; $i++) { $stmt = $con->prepare('INSERT INTO tt VALUES (:id, :name)'); $stmt->execute(array(':id' => $i, ':name' => 'Some text bla bla bla')); } $t2 = microtime(true); $dt = (int)(($t2 - $t1) * 1000); echo "Prepared not reused: $dt\r\n"; } function test_prep_multi($con) { delete($con); $t1 = microtime(true); $stmt = $con->prepare('INSERT INTO tt VALUES (:id, :name)'); for($i = 0; $i < N; $i++) { $stmt->execute(array(':id' => $i, ':name' => 'Some text bla bla bla')); } $t2 = microtime(true); $dt = (int)(($t2 - $t1) * 1000); echo "Prepared reused: $dt\r\n"; } $con = new PDO('mysql:host=localhost;dbname=Test','root', ''); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); test_non_prep($con); test_prep_sing($con); test_prep_multi($con); ?>