Prepared Statement Error - Automatic Quotes

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ragingg
Forum Newbie
Posts: 1
Joined: Wed Sep 02, 2009 2:31 pm

Prepared Statement Error - Automatic Quotes

Post by ragingg »

Hi all,

I'm trying to use PDO to execute MySQL statements, but I'm running into an issue... Here is the code:

Code: Select all

$sql = 'SELECT   *
    FROM     product
    WHERE    display = 1 OR display = 3
    ORDER BY display DESC
    LIMIT    :start_item, :products_per_page';
    
// Build the parameters array
    $params = array(
    ':products_per_page' => PRODUCTS_PER_PAGE,
    ':start_item' => $start_item;
 
        $statement_handler = $database_handler->prepare($sql);
    // Execute the query
    $statement_handler->execute($params);
    // Fetch result
    $result = $statement_handler->fetchAll($fetchStyle);
 
 
The problem is that when I prepare the $sql statement, I expect the following:
SELECT * FROM product WHERE display = 1 OR display = 3 ORDER BY display DESC LIMIT 0, 4

What I actually get is this...
SELECT * FROM product WHERE display = 1 OR display = 3 ORDER BY display DESC LIMIT '0', '4'

The PDO prepare statement seems to be putting quotes around my integers, which causes errors in the MySQL execution. How can I stop it from doing this?

Thank you!
Post Reply