Skip to content

Commit 63c558b

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #44643: bound parameters ignore explicit type definitions
2 parents e96b984 + 23a3bbb commit 63c558b

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ PHP NEWS
2828
. Fixed bug #81015 (Opcache optimization assumes wrong part of ternary
2929
operator in if-condition). (Nikita)
3030

31+
- PDO_ODBC:
32+
. Fixed bug #44643 (bound parameters ignore explicit type definitions). (cmb)
33+
3134
- PDO_pgsql:
3235
. Reverted bug fix for #80892 (PDO::PARAM_INT is treated the same as
3336
PDO::PARAM_STR). (Matteo)

ext/pdo_odbc/odbc_stmt.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,16 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p
321321
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
322322
/* MS Access, for instance, doesn't support SQLDescribeParam,
323323
* so we need to guess */
324-
sqltype = PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB ?
325-
SQL_LONGVARBINARY :
326-
SQL_LONGVARCHAR;
324+
switch (PDO_PARAM_TYPE(param->param_type)) {
325+
case PDO_PARAM_INT:
326+
sqltype = SQL_INTEGER;
327+
break;
328+
case PDO_PARAM_LOB:
329+
sqltype = SQL_LONGVARBINARY;
330+
break;
331+
default:
332+
sqltype = SQL_LONGVARCHAR;
333+
}
327334
precision = 4000;
328335
scale = 5;
329336
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)