Jack M.
Jack M.

Reputation: 3804

PHP PDO Bind tripping with variable types

I have a PDO connection (persistent) and I am doing queries like this:

$sql=$pdo->prepare("SELECT * FROM table WHERE myindex=:PDO_myIndex");
$sql->bindParam(':PDO_myIndex', $myIndex);
$sql->execute();

The problem is $myIndex is INT before bindParam (confirmed with var_dump) and then it becomes STRING after bindParam (before the execute).

Is this a normal or known behavior ?

Upvotes: 0

Views: 37

Answers (2)

user4094161
user4094161

Reputation:

Yes that is an issue, check manual comment.

The third parameter stands for datatype - you can use that one.

Upvotes: 1

Hanky Panky
Hanky Panky

Reputation: 46910

You can explicitly specify that using the third parameter available

$sql->bindParam(':PDO_myIndex', $myIndex, PDO::PARAM_INT);
                                          ^

Manual

Upvotes: 3

Related Questions