Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:32:14+00:00 2026-06-01T19:32:14+00:00

SELECT id, content, date FROM comment WHERE post = ? ORDER BY date DESC

  • 0
SELECT id, content, date
FROM comment
WHERE post = ?
ORDER BY date DESC
LIMIT ?, ?

With PDO (I’m using MAMP 2.0.5 that has Apache 2.2.21, PHP up to 5.3.6, and MySQL 5.5.9) prepared statement this doesn’t work, if I change the query with

LIMIT 0, 10

it works.

I see in the bugs of MySQL that this was a bug in previous version but I can’t understand if this is still to be fixed.

If this is still a problem, there is a way to select a range of rows in another way?

code:

$comments = $db->prepare($query); 
/* where $db is the PDO object */ 
$comments->execute(array($post, $min, $max)); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:32:17+00:00Added an answer on June 1, 2026 at 7:32 pm

    Here’s the problem:

    $comments = $db->prepare($query); 
    /* where $db is the PDO object */ 
    $comments->execute(array($post, $min, $max));
    

    The manual page for PDOStatement::execute() says (emphasis mine):

    Parameters

    input_parameters An array of values with as many elements as there are
    bound parameters in the SQL statement being executed. All values are
    treated as PDO::PARAM_STR
    .

    Thus your parameters are getting inserted as strings, so the final SQL code looks like this:

    LIMIT '0', '10'
    

    This is a particular case where MySQL will not cast to number but trigger a parse error:

    mysql> SELECT 1 LIMIT 0, 10;
    +---+
    | 1 |
    +---+
    | 1 |
    +---+
    1 row in set (0.00 sec)
    
    mysql> SELECT 1 LIMIT '0', '10';
    ERROR 1064 (42000): 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', '10'' at line 1
    

    What docs have to say:

    The LIMIT clause can be used to constrain the number of rows
    returned by the SELECT statement. LIMIT takes one or two numeric
    arguments, which must both be nonnegative integer constants, with
    these exceptions:

    • Within prepared statements, LIMIT parameters can be specified using ? placeholder markers.

    • Within stored programs, LIMIT parameters can be specified using integer-valued routine parameters or local variables.

    Your choices include:

    • Bind parameters one by one so you can set a type:

      $comments->bindParam(1, $post, PDO::PARAM_STR);
      $comments->bindParam(2, $min, PDO::PARAM_INT);
      $comments->bindParam(3, $min, PDO::PARAM_INT);
      
    • Do not pass those values as parameters:

      $query = sprintf('SELECT id, content, date
          FROM comment
          WHERE post = ?
          ORDER BY date DESC
          LIMIT %d, %d', $min, $max);
      
    • Disable emulated prepares (the MySQL driver has a bug/feature that will make it quote numeric arguments):

      $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL query: SELECT ArticleCategories.Title AS Category, Articles.Title, Articles.[Content], Articles.Date FROM ArticleCategories INNER JOIN Articles
I have two mysql queries: $sql = SELECT * FROM content WHERE threadName LIKE
What am I doing wrong with this: $sql = SELECT * FROM content WHERE
SELECT avg(con_hits) as avg_hits FROM content WHERE con_type = 1 AND con_posttime < $twelve_hrs_ago
How to return table name in the below mysql fulltext union search? (SELECT title,content,date
$query4 = mysql_query(SELECT * FROM comments WHERE content_id = '$id' AND content = 'thread'
I have the following MySQL query: SELECT SUM(IF(num_content>3,3,num_content)) FROM ( SELECT DATE(FROM_UNIXTIME(content_timestamp)) as dt,
When I post comments using the form field from the loop, the specific ID
I have a question about fiscal date literals in the Force.com API ( http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_dateformats.htm
I added a bottom bar on NSWindow in IB by select Content Border-Large Bottom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.