xref: /PHP-8.1/ext/pdo/tests/bug_73234.phpt (revision 30589258)
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');
9require_once $dir . 'pdo_test.inc';
10PDOTest::skip();
11
12$db = PDOTest::factory();
13if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
14    die("xfail PDO::PARAM_NULL is not honored by OCI driver, related with bug #81586");
15}
16?>
17--FILE--
18<?php
19if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
20require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
21
22$db = PDOTest::factory();
23$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
24
25switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
26    case 'dblib':
27        $sql = 'CREATE TABLE test(id INT NULL)';
28        break;
29    default:
30        $sql = 'CREATE TABLE test(id INT)';
31        break;
32}
33$db->exec($sql);
34
35$stmt = $db->prepare('INSERT INTO test VALUES(:value)');
36
37$stmt->bindValue(':value', 0, PDO::PARAM_NULL);
38$stmt->execute();
39
40$stmt->bindValue(':value', null, PDO::PARAM_NULL);
41$stmt->execute();
42
43$stmt = $db->query('SELECT * FROM test');
44var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
45?>
46--EXPECT--
47array(2) {
48  [0]=>
49  array(1) {
50    ["id"]=>
51    NULL
52  }
53  [1]=>
54  array(1) {
55    ["id"]=>
56    NULL
57  }
58}
59