How to change the Prepared Statement wildcard value?

Asked

Viewed 134 times

2

Suppose I have an appointment with prepare that is this way:

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

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

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

1 answer

2

Use the functions bindParam and bindValue. 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);
  • 1

    I am using the Adodb library. I tried this way but could not, any suggestions? $rs = $db->Execute('select name from table Where val=:key', array('key' => 10));

  • From the ADODB documentation (http://phplens.com/lens/adodb/docs-adodb.htm), that seems to me to be the case. Running the query directly in the database, you get some result?

  • This answer presupposes the use of PDO, right? I don’t think ADO has bindParam.

  • Actually the parameters come in array which is the second parameter of the method Execute.

  • the ADO has bind. In the database I did not get to test yet but in php debug it accuses error next to ":" after the sign of "=".

  • Try to separate them by space or use ? instead of named parameters.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.