Skip to content

Commit 320d605

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #44643: bound parameters ignore explicit type definitions
2 parents 16d59a5 + 63c558b commit 320d605

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

ext/pdo_odbc/odbc_stmt.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,16 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p
318318
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
319319
/* MS Access, for instance, doesn't support SQLDescribeParam,
320320
* so we need to guess */
321-
sqltype = PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB ?
322-
SQL_LONGVARBINARY :
323-
SQL_LONGVARCHAR;
321+
switch (PDO_PARAM_TYPE(param->param_type)) {
322+
case PDO_PARAM_INT:
323+
sqltype = SQL_INTEGER;
324+
break;
325+
case PDO_PARAM_LOB:
326+
sqltype = SQL_LONGVARBINARY;
327+
break;
328+
default:
329+
sqltype = SQL_LONGVARCHAR;
330+
}
324331
precision = 4000;
325332
scale = 5;
326333
nullable = 1;

ext/pdo_odbc/tests/bug44643.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #44643 (bound parameters ignore explicit type definitions)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_odbc')) die('skip pdo_odbc extension not available');
6+
require 'ext/pdo/tests/pdo_test.inc';
7+
PDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
require 'ext/pdo/tests/pdo_test.inc';
12+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
13+
$sql = "SELECT * FROM (SELECT 'test' = :id1) a WHERE a.test = :id2";
14+
$stmt = $db->prepare($sql);
15+
$id1 = 1;
16+
$stmt->bindParam(':id1', $id1, PDO::PARAM_INT);
17+
$id2 = 1;
18+
$stmt->bindParam(':id2', $id2, PDO::PARAM_INT);
19+
var_dump($stmt->execute());
20+
?>
21+
--EXPECT--
22+
bool(true)

0 commit comments

Comments
 (0)