How to apply bindValue method in LIMIT clause?

后端 未结 10 2418
旧巷少年郎
旧巷少年郎 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:17

    Since nobody has explained why this is happening, I'm adding an answer. The reason it is behaving this was is because you are using trim(). If you look at the PHP manual for trim, the return type is string. You are then trying to pass this as PDO::PARAM_INT. A few ways to get around this are:

    1. Use filter_var($integer, FILTER_VALIDATE_NUMBER_INT) to make sure you are passing an integer.
    2. As others said, using intval()
    3. Casting with (int)
    4. Checking if it is an integer with is_int()

    There are plenty more ways, but this is basically the root cause.

提交回复
热议问题