xref: /PHP-8.2/ext/pdo/tests/bug_73234.phpt (revision ae95644f)
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 test(id INT NULL)';
29        break;
30    default:
31        $sql = 'CREATE TABLE test(id INT)';
32        break;
33}
34$db->exec($sql);
35
36$stmt = $db->prepare('INSERT INTO test 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 test');
45var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
46?>
47--EXPECT--
48array(2) {
49  [0]=>
50  array(1) {
51    ["id"]=>
52    NULL
53  }
54  [1]=>
55  array(1) {
56    ["id"]=>
57    NULL
58  }
59}
60