Orange-OpenSource / YACassandraPDO

Cassandra PDO Driver fork
Apache License 2.0
85 stars 32 forks source link

Invalid parameter number: no parameters were bound #63

Open blat opened 10 years ago

blat commented 10 years ago

Query with \' + ? can't be prepared.

Example:

$db = new PDO("cassandra:host=localhost;port=9160");
$query = "INSERT INTO test (a, b) VALUES (" . $db->quote("f\'oo") . ", " . $db->quote("bar?") . ")";
$stmt = $db->prepare($query);
$stmt->execute();

Result:

PHP Warning:  PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: no parameters were bound

But, $query is valid:

INSERT INTO test (a, b) VALUES ('f\''oo', 'bar?');

Copy/paste it in a cqlsh, it works!

ghost commented 10 years ago

Try

$db = new PDO("cassandra:host=localhost;port=9160");
$stmt = $db->prepare("INSERT INTO test (a, b) VALUES (:a, :b);");
$stmt->bindValue(':a', 'f\'oo');
$stmt->bindValue(':b', 'bar?');
$stmt->execute();
blat commented 10 years ago

Yes, I know.

This works too:

$db = new PDO("cassandra:host=localhost;port=9160");
$query = "INSERT INTO test (a, b) VALUES (" . $db->quote("f\'oo") . ", " . $db->quote("bar?") . ")";
$db->query($query);

But my first example works with PDO MySQL. It's not a critical issue, but it's a bug :)

mlornac-orange commented 10 years ago

I am not sure this is a bug. The string "f\'oo" is not correct. It should be written either "f'oo" or "f\'oo" if you want to insert a backslash in your string.

You escape the single quote if you write your string in single quotes. eg. 'f\'oo'

blat commented 10 years ago

I want to insert f\'oo (OK, it's tricky, but why not...) I call quote() to escape my string. quote() returns f\''oo.

There is two possible issues:

In both cases, there is a bug in Cassandra PDO.