How to change the value of the joker in the Prepared Statement?

2

Suppose I have a query with prepare that looks like this:

select senha from usuarios where id=? //or id2=?, array($id,$id2); (é só um exemplo).

My intention is to change the ? to any other value that I choose within the array and not that it picks up the order that is inside the array.

For example, the first id=? takes the value from position 2 of the array. I am using postgresql database and PHP programming language

    
asked by anonymous 17.02.2014 / 17:55

1 answer

2

Use the bindParam and bindValue functions. For example:

$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);

Or:

$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)");
$stmt->bindValue(1, $name);
$stmt->bindValue(2, $value);
    
17.02.2014 / 18:06