xref: /PHP-7.3/ext/pdo/tests/bug_43130.phpt (revision 463fd047)
1--TEST--
2PDO Common: Bug #43130 (Bound parameters cannot have - in their name)
3--SKIPIF--
4<?php # vim:ft=php
5if (!extension_loaded('pdo')) die('skip');
6$dir = getenv('REDIR_TEST_DIR');
7if (false == $dir) die('skip no driver');
8if (!strncasecmp(getenv('PDOTEST_DSN'), 'sqlite', strlen('sqlite'))) die('skip not relevant for sqlite driver');
9if (!strncasecmp(getenv('PDOTEST_DSN'), 'pgsql', strlen('pgsql'))) die('skip not relevant for pgsql driver');
10if (!strncasecmp(getenv('PDOTEST_DSN'), 'oci', strlen('oci'))) die('skip not relevant for oci driver - Hyphen is not legal for bind names in Oracle DB');
11if (!strncasecmp(getenv('PDOTEST_DSN'), 'firebird', strlen('firebird'))) die('skip not relevant for firebird driver');
12if (!strncasecmp(getenv('PDOTEST_DSN'), 'odbc', strlen('odbc'))) die('skip not relevant for odbc driver');
13require_once $dir . 'pdo_test.inc';
14PDOTest::skip();
15?>
16--FILE--
17<?php
18if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
19require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
20$db = PDOTest::factory();
21
22if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql')
23	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
24
25$db->exec("CREATE TABLE test (a varchar(100), b varchar(100), c varchar(100))");
26
27for ($i = 0; $i < 5; $i++) {
28	$db->exec("INSERT INTO test (a,b,c) VALUES('test".$i."','".$i."','".$i."')");
29}
30
31$stmt = $db->prepare("SELECT a FROM test WHERE b=:id-value");
32$stmt->bindParam(':id-value', $id);
33$id = '1';
34$stmt->execute();
35var_dump($stmt->fetch(PDO::FETCH_COLUMN));
36?>
37--EXPECTF--
38Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in %s on line %d
39
40Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d
41bool(false)
42