[PECL-CVS] [pecl-database-pdo_oci] pdo_oci_param_bool_fix: Fix binding of PDO::PARAM_BOOL (Issue #12)

[email protected] (Sharad Chandran R)
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Sharad Chandran R (sharadraju)
Date: 2026-01-05T16:33:24+05:30

Commit: https://github.com/php/pecl-database-pdo_oci/commit/c8595b6c172b8eb06d867cd2d367ee1b7d327495
Raw diff: https://github.com/php/pecl-database-pdo_oci/commit/c8595b6c172b8eb06d867cd2d367ee1b7d327495.diff

Fix binding of PDO::PARAM_BOOL (Issue #12)

Changed paths:
  A  tests/pdo_oci_bind_bool.phpt
  M  oci_statement.c


Diff:

diff --git a/oci_statement.c b/oci_statement.c
index 96ecfb8..79788d7 100644
--- a/oci_statement.c
+++ b/oci_statement.c
@@ -225,9 +225,20 @@ static sb4 oci_bind_input_cb(dvoid *ctx, OCIBind *bindp, ub4 iter, ub4 index, dv
 		*bufpp = 0;
 		*alenp = -1;
 	} else if (!P->thing) {
-		/* regular string bind */
-		if (!try_convert_to_string(parameter)) {
-			return OCI_ERROR;
+		if(PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL) {
+			/* Handle boolean as "1"/ "0" */
+			if(zval_is_true(parameter)) {
+				zval_ptr_dtor(parameter);
+				ZVAL_CHAR(parameter, '1');
+			} else {
+				zval_ptr_dtor(parameter);
+				ZVAL_CHAR(parameter, '0');
+			}
+		} else {
+			/* regular string bind */
+			if (!try_convert_to_string(parameter)) {
+				return OCI_ERROR;
+			}
 		}
 		*bufpp = Z_STRVAL_P(parameter);
 		*alenp = (ub4) Z_STRLEN_P(parameter);
diff --git a/tests/pdo_oci_bind_bool.phpt b/tests/pdo_oci_bind_bool.phpt
new file mode 100644
index 0000000..d88c8ca
--- /dev/null
+++ b/tests/pdo_oci_bind_bool.phpt
@@ -0,0 +1,34 @@
+--TEST--
+PDO_OCI: Bind boolean parameters
+--EXTENSIONS--
+pdo
+pdo_oci
+--SKIPIF--
+<?php
+require(getenv('PDO_TEST_DIR').'/pdo_test.inc');
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require_once(getenv('PDO_TEST_DIR').'/pdo_test.inc');
+
+$conn = PDOTest::factory();
+
+$stmt = $conn->prepare('SELECT ?, ? FROM DUAL');
+$stmt->bindValue(1, true, PDO::PARAM_BOOL);
+$stmt->bindValue(2, false, PDO::PARAM_BOOL);
+$stmt->execute();
+var_dump($stmt->fetchAll(PDO::FETCH_NUM));
+
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  array(2) {
+    [0]=>
+    string(1) "1"
+    [1]=>
+    string(1) "0"
+  }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.