PDO bindParam issue about LIMIT

Question

I have a issue about PDO. This code block is worked

$MyQuery = $db->prepare("UPDATE project
SET
PeopleId=:PID,
UserId=:UID
WHERE
PeopleId=:PeopleId
AND
UserID=:UserID
AND
(
                alpha = 0
                OR alpha IS NULL
            )  LIMIT ".$Adet);

            $MyQuery->bindParam(":PID", $PID, PDO::PARAM_INT);
            $MyQuery->bindParam(":UID", $UID, PDO::PARAM_INT);
            $MyQuery->bindParam(":PeopleId", $PeopleId, PDO::PARAM_INT);
            $MyQuery->bindParam(":UserID", $UserID, PDO::PARAM_INT);
            $MyQuery->execute();

But it didnt work.

$MyQuery = $db->prepare("UPDATE project
SET
PeopleId=:PID,
UserId=:UID
WHERE
PeopleId=:PeopleId
AND
UserID=:UserID
AND
(
                alpha = 0
                OR alpha IS NULL
            )  LIMIT :Count");

            $MyQuery->bindParam(":PID", $PID, PDO::PARAM_INT);
            $MyQuery->bindParam(":UID", $UID, PDO::PARAM_INT);
            $MyQuery->bindParam(":PeopleId", $PeopleId, PDO::PARAM_INT);
            $MyQuery->bindParam(":UserID", $UserID, PDO::PARAM_INT);
            $MyQuery->bindParam(":Count",$Count, PDO::PARAM_INT);
            $MyQuery->execute();

Where is my fault ? I couldn't find anything. I guess there is a mistake. I converted the $Count to Integer but it is not worked again . Can anyone help me about this issue ?


Show source
| pdo   | php   | mysql   2017-01-06 18:01 1 Answers

Answers to PDO bindParam issue about LIMIT ( 1 )

  1. 2017-01-06 18:01

    force the $Count var to be an intger,

    $MyQuery->bindParam(":Count", (int) $Count, PDO::PARAM_INT);
    

    mabye trim too: (edited after comment of Muhammed Almaz tnx :D)

    $Count = trim($Count)    
    $MyQuery->bindParam(":Count", (int) $Count, PDO::PARAM_INT);
    

Leave a reply to - PDO bindParam issue about LIMIT

◀ Go back