How to apply bindValue method in LIMIT clause?

后端 未结 10 2417
旧巷少年郎
旧巷少年郎 2020-11-21 04:28

Here is a snapshot of my code:

$fetchPictures = $PDO->prepare(\"SELECT * 
    FROM pictures 
    WHERE album = :albumId 
    ORDER BY id ASC 
    LIMIT :s         


        
10条回答
  •  情话喂你
    2020-11-21 05:22

    PDO::ATTR_EMULATE_PREPARES gave me the

    Driver does not support this function: This driver doesn't support setting attributes' error.

    My workaround was to set a $limit variable as a string, then combine it in the prepare statement as in the following example:

    $limit = ' LIMIT ' . $from . ', ' . $max_results;
    $stmt = $pdo->prepare( 'SELECT * FROM users WHERE company_id = :cid ORDER BY name ASC' . $limit . ';' );
    try {
        $stmt->execute( array( ':cid' => $company_id ) );
        ...
    }
    catch ( Exception $e ) {
        ...
    }
    

提交回复
热议问题