xref: /PHP-8.3/ext/pdo/tests/pdo_028.phpt (revision 74859783)
1--TEST--
2PDO Common: bindValue
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
18$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10), val3 VARCHAR(10))');
19$stmt = $db->prepare('INSERT INTO test values (1, ?, ?, ?)');
20
21$data = array("one", "two", "three");
22
23foreach ($data as $i => $v) {
24    $stmt->bindValue($i+1, $v);
25}
26$stmt->execute();
27
28$stmt = $db->prepare('SELECT * from test');
29$stmt->execute();
30
31var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
32?>
33--EXPECT--
34array(1) {
35  [0]=>
36  array(4) {
37    ["id"]=>
38    string(1) "1"
39    ["val1"]=>
40    string(3) "one"
41    ["val2"]=>
42    string(3) "two"
43    ["val3"]=>
44    string(5) "three"
45  }
46}
47