2

Generic topic I know. Its hard to be specific in a topic. Anyway I have problem with this sql logic:

"SELECT * FROM imagecomment WHERE filename = :filename ORDER BY comment_timestamp DESC LIMIT '$min', '$max'"; 

When I try the same logic but with integers directly in the sql logic it works. The variables min and max are integers:

int(10) int(20) I get this when var_dump() them. I also tried to bindValue() the variables (as I usually do) to two parameters but it still didn't work.

2
  • 1
    do not escape your LIMIT values Commented Oct 18, 2012 at 12:52
  • 2
    Don't need single quotes around them Commented Oct 18, 2012 at 12:54

2 Answers 2

5

You're using this in a PDOStatement, right? (since you're using :filename)

$db = new PDO(); //assume you have this set

$stmt = $db->prepare( "SELECT * FROM imagecomment WHERE filename = :filename ORDER BY comment_timestamp DESC LIMIT :min, :max"; $stmt->bindValue(':filename', $filename); $stmt->bindValue(':min', $min); $stmt->bindValue(':max', $max); $stmt->execute(); 

And you should be able to fetch your results, If that doesn't work, let me know what error you're getting back from the PDOStatement.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not getting any result set when using parameters instead of integers directly in the sql logic "SELECT * FROM imagecomment WHERE filename = :filename ORDER BY comment_timestamp DESC LIMIT :min, :max"; and bind the values to the parameters exactly as you've done. I've also been told before that I should just insert integers directly. Whats your thoughts about this?
4
 "SELECT * FROM imagecomment WHERE filename = :filename ORDER BY comment_timestamp DESC LIMIT $min, $max"; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.