Home » Database » MDB2 » Bug #10239
execute() misinterprets MySQL's user defined variables
Details
| Submitted | 2007-03-01 23:13 UTC |
|---|---|
| From | mjohnson at pitsco dot com |
| Assigned | quipo |
| Status | Closed |
| Package | MDB2 |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2007-03-01 23:13 UTC] mjohnson at pitsco dot com
Description:
------------
When using prepared statements, MySQL user defined variables are mis-interpreted as named place holders.
When dealing with more complicated situations, the error is different. We have a sort of query library we use internally and when running the same query as the test script the result is:
MDB2 Error: syntax error
_doquery: [Error message: Could not execute statement]
[Last executed query: PREPARE MDB2_STATEMENT_mysql_ef8a43da87c7f66c71cbc6e7e1427102 FROM 'SELECT @x?']
[Native code: 1064]
[Native message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1]
(note the variables being passed in here are overkill for query, which I substituted in for testing)
Test script:
---------------
<?php
require_once('MDB2.php');
$dsn = 'mysql://test:testpassword@localhost/test';
$db =& MDB2::singleton($dsn);
$prep =& $db->prepare('SELECT @x:=5');
$res = $prep->execute();
if (MDB2::isError($res)) {
echo "Error.\n";
echo $res->message . "\n";
echo $res->userinfo . "\n";
}
?>
Expected result:
----------------
Expect to see nothing.
Actual result:
--------------
Error.
MDB2 Error: not found
_execute: [Error message: Unable to bind to missing placeholder: SELECT @x:=5]
[Native code: ]
[Native message: ]