]> granicus.if.org Git - php/commitdiff
Closes PECL #5809; PDOStatement::execute(array(...)) would modify its args.
authorWez Furlong <wez@php.net>
Sat, 29 Oct 2005 03:01:19 +0000 (03:01 +0000)
committerWez Furlong <wez@php.net>
Sat, 29 Oct 2005 03:01:19 +0000 (03:01 +0000)
It should behave like bindValue() not bindParam().

ext/pdo/pdo_stmt.c
ext/pdo/tests/pecl_bug_5809.phpt [new file with mode: 0644]

index ff9b273e428a098fc37fe07def3ff36ed0b5a893..64bc86c5ac799d3284f25f5b41db046854d114ea 100755 (executable)
@@ -368,11 +368,15 @@ static PHP_METHOD(PDOStatement, execute)
                        }
 
                        param.param_type = PDO_PARAM_STR;
-                       param.parameter = *tmp;
+                       MAKE_STD_ZVAL(param.parameter);
+                       *param.parameter = **tmp;
+                       zval_copy_ctor(param.parameter);
 
                        if (!really_register_bound_param(&param, stmt, 1 TSRMLS_CC)) {
+                               zval_ptr_dtor(&param.parameter);
                                RETURN_FALSE;
                        }
+                       zval_ptr_dtor(&param.parameter);
 
                        zend_hash_move_forward(Z_ARRVAL_P(input_params));
                }
diff --git a/ext/pdo/tests/pecl_bug_5809.phpt b/ext/pdo/tests/pecl_bug_5809.phpt
new file mode 100644 (file)
index 0000000..66f8c21
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+PDO Common: PECL Bug #5809 PDOStatement::execute(array()) changes param
+--SKIPIF--
+<?php # vim:ft=php:
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+$db = PDOTest::factory();
+
+$db->exec("CREATE TABLE test (id int(10) NOT NULL, PRIMARY KEY (id))");
+$db->exec("INSERT INTO test (id) VALUES (1)");
+
+$values = array(1);
+var_dump($values);
+$stmt = $db->prepare('SELECT * FROM test WHERE id = ?');
+$stmt->execute($values);
+var_dump($values);
+
+--EXPECT--
+array(1) {
+  [0]=>
+  int(1)
+}
+array(1) {
+  [0]=>
+  int(1)
+}