I use the following sql to get the value of the que_id field of a specific row of my table, and it works fine. Note that que_id (auto-incremented) and line numbers do not match.
$qry_que_getid = $connexion->query('SELECT somefield FROM table ORDER BY somefield ASC LIMIT '.$lineNumberSeeked.', 1'); $row = $qry_que_getid->fetch(PDO::FETCH_ASSOC); echo $row['que_id'];
When I try to convert this query into a prepared query as follows, I have an error and I don’t understand:
$qry_que_getid = $connexion->prepare('SELECT somefield FROM table ORDER BY somefield ASC LIMIT ?, 1'); $qry_que_getid->execute(array(4)); $row = $qry_que_getid->fetch(PDO::FETCH_ASSOC); echo $row['que_id'];
I get the following SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''3', 1' at line 1 error SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''3', 1' at line 1 SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''3', 1' at line 1
Hope somene can help me understand. Thanks in advance. Greetings. Mark.
Marc
source share