PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » MDB2 » Bug #10239

execute() misinterprets MySQL's user defined variables

Details

Submitted2007-03-01 23:13 UTC
Frommjohnson at pitsco dot com
Assignedquipo
StatusClosed
PackageMDB2
PHP VersionIrrelevant
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: ]