PDOStatement::bindValue
PDOStatement::bindValue - Bind a value to a parameter (PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
Description
Syntax
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 the SQL statement used for preprocessing.
Parameters
** parameter**
The parameter identifier. For prepared statements using named placeholders, this is a parameter name of the form :name. For prepared statements using question mark placeholders, this is the 1-based parameter position.
** value**
The value bound to the parameter
** data_type**
Use the PDO::PARAM_* constant to explicitly specify the parameter type.
Return Value
Returns TRUE on success, or FALSE on failure.
Example
Execute a prepared statement using named placeholders
prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->bindValue(':calories', $calories, PDO::PARAM_INT);
$sth->bindValue(':colour', $colour, PDO::PARAM_STR);
$sth->execute();
?>
Execute a prepared statement using question mark placeholders
prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->bindValue(1, $calories, PDO::PARAM_INT);
$sth->bindValue(2, $colour, PDO::PARAM_STR);
$sth->execute();
?>
PHP PDO Reference Manual