I was trying to get some data from an AccessDB file using MDBTools in PHP. All the normal SQL queries are working except ORDER BY and GROUP BY
When I use ORDER BY I am getting error
Error at Line : syntax error near ORDER
syntax error near ORDER
Got no result for 'SELECT * FROM CHECKINOUT ORDER BY CHECKTIME DESC' command
This is the code
$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;";
$conn = new PDO($dataSourceName);
$q = $conn->prepare("SELECT * FROM CHECKINOUT ORDER BY CHECKTIME DESC");
$q->execute();
$result = $q->fetchAll(PDO::FETCH_OBJ);
print_r($result);
[Update] When i used the above query in mysqli, it worked like charm. I created the database similar to the database on the access db file and used this code,
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$row = $conn->query("SELECT USERID, CHECKTIME, CHECKTYPE FROM CHECKINOUT ORDER BY USERID DESC");
$result = $row->fetch_object();
print_r($result);
The above code worked like charm. But not when using PDO.