|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-05-31 21:22 UTC] Jan_Oonk at hotmail dot com
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""';
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
Shorter independent reproducable testscript. You only need an Access (.mdb/.accdb) database with at least one table called 'film' and a column 'titel'. Put some records in it. At least 1 with 'Batman'. //also using a older Access version of the database "film.mdb" didn't work //be sure to use full/absolute pathname $dbnameFile="C:\\wamp\\www\\elearning2\\databases\\film.accdb"; $username="user1"; $password="secret"; $accessdriver="{Microsoft Access Driver (*.mdb, *.accdb)}"; $dbDB = new PDO("odbc:Driver=$accessdriver;Dbq=$dbnameFile", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); //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>"; } $dbDB=null;//You can leave the username and password empty: $username=""; $password=""; //Also you can use a different older accessdriver. This depends on your configuration $accessdriver="{Microsoft Access Driver (*.mdb)}"; //In that case make sure it's an older Access .mdb format and check file extension is .mdb $dbnameFile="C:\\wamp\\www\\elearning2\\databases\\film.mdb";