xref: /php-src/ext/pdo/tests/bug_73234.phpt (revision f4a5db3e)
1--TEST--
2PDO Common: Bug #73234 (Emulated statements let value dictate parameter type)
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9if (str_starts_with(getenv('PDOTEST_DSN'), "firebird")) die('xfail firebird driver does not behave as expected');
10require_once $dir . 'pdo_test.inc';
11PDOTest::skip();
12
13$db = PDOTest::factory();
14if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
15    die("xfail PDO::PARAM_NULL is not honored by OCI driver, related with bug #81586");
16}
17?>
18--FILE--
19<?php
20if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
21require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
22
23$db = PDOTest::factory();
24$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
25
26switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
27    case 'dblib':
28        $sql = 'CREATE TABLE test73234(id INT NULL)';
29        break;
30    default:
31        $sql = 'CREATE TABLE test73234(id INT)';
32        break;
33}
34$db->exec($sql);
35
36$stmt = $db->prepare('INSERT INTO test73234 VALUES(:value)');
37
38$stmt->bindValue(':value', 0, PDO::PARAM_NULL);
39$stmt->execute();
40
41$stmt->bindValue(':value', null, PDO::PARAM_NULL);
42$stmt->execute();
43
44$stmt = $db->query('SELECT * FROM test73234');
45var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
46?>
47--CLEAN--
48<?php
49require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
50$db = PDOTest::factory();
51PDOTest::dropTableIfExists($db, "test73234");
52?>
53--EXPECT--
54array(2) {
55  [0]=>
56  array(1) {
57    ["id"]=>
58    NULL
59  }
60  [1]=>
61  array(1) {
62    ["id"]=>
63    NULL
64  }
65}
66