Home » Database » MDB2 » Bug #9863
Patch to fix "Unable to bind to missing placeholder: 0" error with autoExecute
Details
| Submitted | 2007-01-18 08:37 UTC |
|---|---|
| From | dranger at export-japan dot com |
| Assigned | quipo |
| Status | Bogus |
| Package | MDB2 |
| PHP Version | 4.4.4 |
| OS | All |
| Roadmaps | (Not assigned) |
Comments
[2007-01-18 08:37 UTC] dranger at export-japan dot com
Description:
------------
autoExecute fails when trying to bind values.
Test script:
---------------
$db->extended->autoExecute("table", array("field1"=>$value, "field2"=>$value2), MDB2_AUTOQUERY_UPDATE, "id=$id");
Patch:
--- MDB2.php 2007-01-18 17:16:52.000000000 +0900
+++ MDB2.php 2007-01-18 17:17:36.000000000 +0900
@@ -3914,7 +3914,7 @@
if (!is_numeric($parameter)) {
$parameter = preg_replace('/^:(.*)$/', '\\1', $parameter);
}
- if (!in_array($parameter, $this->positions)) {
+ if (!array_key_exists($parameter, $this->positions)) {
return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
}
Expected result:
----------------
It to work
Actual result:
--------------
"Unable to bind to missing placeholder: 0"
[2007-01-19 00:07 UTC] dranger at export-japan dot com
This PHP script fails:
<?php
require_once('MDB2.php');
$dsn = array("phptype" => DB_TYPE,
"hostspec" => DB_HOST,
"username" => DB_USER,
"password" => DB_PWD,
"database" => DB_NAME);
$options = array("debug" => DEBUG_LEVEL,
"portability" => MDB2_PORTABILITY_NONE);
$db =& MDB2::connect($dsn, $options);
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$db->loadModule('Extended');
$table = $_GET["table"];
$id = $_GET["id"];
$fields = array();
if(isset($_GET["field"]))
{ $field = $_GET["field"];
$value = $_POST["value"];
$fields[$field] = $value;
}
$result = $db->extended->autoExecute($table, $fields, MDB2_AUTOQUERY_UPDATE, "id = $id");
?>
Regardless of the reproducibility, I'm pretty sure that the function on line 3914 should be array_key_exists() instead on in_array() anyway; it's even like that in _execute.
[2007-01-19 01:51 UTC] dranger at export-japan dot com
Sorry, forgot the SQL data. $table was "tour", and the $fields array was array("name" => "OK"). $id was 10. The "tour" table was basically (name(text), id(int)). DB_TYPE was mysql.
[2007-01-22 04:44 UTC] dranger at export-japan dot com
This is in fact bogus (apologies), and was caused by mixing different versions of the MySQL driver and the core MDB2 files, just in case this happens to anyone else.