1--TEST-- 2PDO Common: PDOStatement::execute with parameters 3--SKIPIF-- 4<?php # vim:ft=php 5if (!extension_loaded('pdo')) die('skip'); 6$dir = getenv('REDIR_TEST_DIR'); 7if (false == $dir) die('skip no driver'); 8require_once $dir . 'pdo_test.inc'; 9PDOTest::skip(); 10?> 11--FILE-- 12<?php 13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/'); 14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 15$db = PDOTest::factory(); 16 17if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { 18 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); 19} 20 21$db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))'); 22 23$select = $db->prepare('SELECT COUNT(id) FROM test'); 24 25$data = array( 26 array('10', 'Abc', 'zxy'), 27 array('20', 'Def', 'wvu'), 28 array('30', 'Ghi', 'tsr'), 29 array('40', 'Jkl', 'qpo'), 30 array('50', 'Mno', 'nml'), 31 array('60', 'Pqr', 'kji'), 32); 33 34 35// Insert using question mark placeholders 36$stmt = $db->prepare("INSERT INTO test VALUES(?, ?, ?)"); 37foreach ($data as $row) { 38 $stmt->execute($row); 39} 40$select->execute(); 41$num = $select->fetchColumn(); 42echo 'There are ' . $num . " rows in the table.\n"; 43 44// Insert using named parameters 45$stmt2 = $db->prepare("INSERT INTO test VALUES(:first, :second, :third)"); 46foreach ($data as $row) { 47 $stmt2->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1], 48 ':third'=>$row[2])); 49} 50 51$select->execute(); 52$num = $select->fetchColumn(); 53echo 'There are ' . $num . " rows in the table.\n"; 54 55 56?> 57--EXPECT-- 58There are 6 rows in the table. 59There are 12 rows in the table. 60