PDOStatement::bindValue — Bind a value to a parameter (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
bool PDOStatement::bindValue ( mixed $parameter , mixed $value [, int $data_type = PDO::PARAM_STR ] )
Binds a value to the corresponding named placeholder or question mark placeholder in a SQL statement used for preprocessing.
parameter parameter identifier. For prepared statements using named placeholders, the parameter name should be of the form :name. For prepared statements using the question mark placeholder, the parameter position should be indexed starting with 1.
value is bound to the value of the parameter
data_type uses the PDO::PARAM_* constants to explicitly specify the type of the parameter.
Returns TRUE on success, or FALSE on failure.
<?php/* Execute a prepared statement through bound PHP variables*/$calories = 150;$colour = 'red';$sth = $dbh->prepare('SELECT name, color, calories FROM fruit WHERE calories < :calories AND color = :colour');$sth->bindValue(':calories', $calories, PDO::PARAM_INT);$sth->bindValue(':colour', $colour, PDO::PARAM_STR);$sth->execute();?>
<?php/* Execute a prepared statement through bound PHP variables*/$calories = 150;$colour = 'red';$sth = $dbh->prepare('SELECT name, color, calories FROM fruit WHERE calories < ? AND color = ?');$sth->bindValue(1, $calories, PDO::PARAM_INT);$sth->bindValue(2, $colour, PDO::PARAM_STR);$sth->execute();?>