Bug #69736 [NEW]: Correct query which contains double quotes gives error

From: Date: Sun, 31 May 2015 21:22:17 +0000
Subject: Bug #69736 [NEW]: Correct query which contains double quotes gives error
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193039@lists.php.net to get a copy of this message
From:             Jan_Oonk at hotmail dot com
Operating system: Windows 7 SP1
PHP version:      5.5Git-2015-05-31 (Git)
Package:          PDO ODBC
Bug Type:         Bug
Bug description:Correct query which contains double quotes gives error

Description:
------------
Both queries below work inside Microsoft Access 2013:
[1] select * from movie where moviename like 'batman'  
[2] select * from movie where moviename like "batman"

But when I try to run both queries with PHP 5.5.12 and PDO/ODBC only
query 1 works as expected. Query 2 throws an error.

I made a testscript varying with different escape characters/methods and
using different string quotes.
Especially the last 2 testcases #5 and #6 throw a strange error
description. It looks like the double quotes are changed into square
brackets: [ and ].

Test script:
---------------
include "../include/connectDB.php";

//Testcases, comment all but one
//Testcase 1: works
$sql="select * from film where titel like 'Batman'";

//Testcase 2: works
$sql='select * from film where titel like \'Batman\'';

//Testcase 3: COUNT field incorrect: -3010 [Microsoft][ODBC Microsoft
Access Driver] Too few parameters. Expected 1.
$sql="select * from film where titel like \"Batman\"";

//Testcase 4: COUNT field incorrect: -3010 [Microsoft][ODBC Microsoft
Access Driver] Too few parameters. Expected 1.
$sql='select * from film where titel like "Batman"';

//Testcase 5: Syntax error (missing operator) in query expression 'titel
like \[Batman\] 
$sql='select * from film where titel like \"Batman\"';

//Testcase 6: Syntax error (missing operator) in query expression 'titel
like []Batman[]
$sql='select * from film where titel like ""Batman""';

$result=$dbDB->query($sql);
$rows=$result->fetchAll(PDO::FETCH_ASSOC);  
$result->closeCursor();

foreach($rows as $row) {
  echo $row["TITEL"]."\n";
  echo "<br>";
}

include "../include/closedbs.php";

Expected result:
----------------
It should return 1 record with all details about the movie Batman.

Actual result:
--------------
//Testcase 1: works
$sql="select * from film where titel like 'Batman'";

//Testcase 2: works
$sql='select * from film where titel like \'Batman\'';

//Testcase 3: COUNT field incorrect: -3010 [Microsoft][ODBC Microsoft
Access Driver] Too few parameters. Expected 1.
$sql="select * from film where titel like \"Batman\"";

//Testcase 4: COUNT field incorrect: -3010 [Microsoft][ODBC Microsoft
Access Driver] Too few parameters. Expected 1.
$sql='select * from film where titel like "Batman"';

//Testcase 5: Syntax error (missing operator) in query expression 'titel
like \[Batman\] 
$sql='select * from film where titel like \"Batman\"';

//Testcase 6: Syntax error (missing operator) in query expression 'titel
like []Batman[]
$sql='select * from film where titel like ""Batman""';


-- 
Edit bug report at https://bugs.php.net/bug.php?id=69736&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=69736&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=69736&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=69736&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=69736&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=69736&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=69736&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=69736&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=69736&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=69736&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=69736&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=69736&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=69736&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=69736&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69736&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=69736&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=69736&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=69736&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69736&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=69736&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=69736&r=mysqlcfg



Thread (8 messages)

« previous php.bugs (#193039) next »