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