Problem with LIMIT syntax
Posted: Sun Jan 19, 2014 3:30 am
i can't retrieve information from the table when i use the code below;
The SQL below is what works, when used in in phpMyAdmin
The error i am receiving via error_log is the following
PDOStatement::execute(): 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 ''0', '4'' at line 7 in /nanya/search.php on line 74
If i remove the LIMIT clause from the query it works;
any ideas / suggestions appreciated
Edit
Did the same script using mysqli_ functions and it seems the problem (seems to me anyway) lies with the ip address not being 'escaped' (?)
Code: Select all
<?php
$sql = "SELECT
`ip`,
`action_date`
FROM
`admin_logins`
WHERE
`ip` = ? LIMIT ?, ?";
$sth2 = $dbh->prepare($sql);
$sth2->execute(array($ip, 0, 4)); // <- line 74
?>Code: Select all
SELECT *
FROM `admin_logins`
WHERE `ip`= '41.52.92.107'
LIMIT 0, 5
PDOStatement::execute(): 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 ''0', '4'' at line 7 in /nanya/search.php on line 74
If i remove the LIMIT clause from the query it works;
any ideas / suggestions appreciated
Edit
Did the same script using mysqli_ functions and it seems the problem (seems to me anyway) lies with the ip address not being 'escaped' (?)