The difference between PHP Pdostatement object Bindpram (), Bindvalue (), and Bindcolumn, pdostatement
pdostatement::bindparam-binds a parameter to the specified variable name.
Binds a PHP variable to the corresponding named placeholder or question mark placeholder in the SQL statement used as a preprocessing. Unlike Pdostatement::bindvalue (), this variable is bound as a reference and only takes its value when Pdostatement::execute () is called.
Pdostatement::bindvalue-binds a value to a parameter.
Binds a value to the corresponding named placeholder or question mark placeholder in the SQL statement that is used as a preprocessing.
Copy the Code code as follows:
<?php
$stm = $pdo->prepare ("SELECT * from users where user =: User");
$user = "Jack";
That's right
$stm->bindparam (": User", $user);
Error
$stm->bindparam (": User", "Jack");
That's right
$stm->bindvalue (": User", $user);
That's right
$stm->bindvalue (": User", "Jack");
So using Bindparam is the second argument that can be used only with the variable name, not the variable value, and Bindvalue to the use of a specific value.
?>
pdostatement::bindcolumn-binds a column to a PHP variable.
Schedules a specific variable to be bound to a given column in a query result set. Each call to Pdostatement::fetch () or Pdostatement::fetchall () updates all variables bound to the column.
Copy the Code code as follows:
<?php
function ReadData ($DBH) {
$sql = ' SELECT name, colour, calories from fruit ';
try {
$stmt = $DBH-Prepare ($sql);
$stmt, execute ();
/* Bind by column number */
$stmt-Bindcolumn (1, $name);
$stmt-Bindcolumn (2, $colour);
/* Bind by column name */
$stmt-bindcolumn (' calories ', $cals);
while ($row = Fetch from $stmt (PDO:: Fetch_bound)) {
$data = $name. "\ T". $colour. "\ T". $cals. "\ n";
Print $data;
}
}
catch (Pdoexception $e) {
Print $e-getMessage ();
}
}
ReadData ($DBH);
?>
http://www.bkjia.com/PHPjc/915441.html www.bkjia.com true http://www.bkjia.com/PHPjc/915441.html techarticle the difference between PHP Pdostatement object Bindpram (), Bindvalue (), and Bindcolumn, pdostatement pdostatement::bindparam-binds a parameter to the specified variable name. Bind a PHP variable ...