xref: /PHP-8.2/ext/pdo/tests/pdo_024.phpt (revision 74859783)
1--TEST--
2PDO Common: assert that bindParam does not modify parameter
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
18switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
19    case 'dblib':
20        // environment settings can influence how the table is created if specifics are missing
21        // https://msdn.microsoft.com/en-us/library/ms174979.aspx#Nullability Rules Within a Table Definition
22        $sql = 'create table test (id int, name varchar(10) null)';
23        break;
24    default:
25        $sql = 'create table test (id int, name varchar(10))';
26        break;
27}
28$db->exec($sql);
29
30$stmt = $db->prepare('insert into test (id, name) values(0, :name)');
31$name = NULL;
32$before_bind = $name;
33$stmt->bindParam(':name', $name, PDO::PARAM_NULL);
34if ($name !== $before_bind) {
35    echo "bind: fail\n";
36} else {
37    echo "bind: success\n";
38}
39var_dump($stmt->execute());
40var_dump($db->query('select name from test where id=0')->fetchColumn());
41
42?>
43--EXPECT--
44bind: success
45bool(true)
46NULL
47