pdostatement::bindparam-binds a parameter to the specified variable name.
Bind 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 its value is only taken when Pdostatement::execute () is invoked.
Pdostatement::bindvalue-binds a value to a parameter.
Binds a value to the corresponding named placeholder or question-mark placeholder in the SQL statement used as a preprocessing.
Copy 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 can only use variable names, not variable values, and Bindvalue to be able to use specific values.
?>
pdostatement::bindcolumn-bind a column to a PHP variable.
Schedule a specific variable to bind 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 Code code as follows:
<?php
function ReadData ($DBH) {
$sql = ' SELECT name, colour, calories from fruit ';
try {
$stmt = $DBH-> Prepare ($sql);
$stmt-> execute ();
/* By column number binding * *
$stmt-> bindcolumn (1, $name);
$stmt-> Bindcolumn (2, $colour);
/* Bind by column name/*
$stmt-> bindcolumn (' calories ', $cals);
while ($row = $stmt-> Fetch (PDO:: Fetch_bound)) {
$data = $name. "\ T". $colour. "\ T". $cals. "\ n";
Print $data;
}
}
catch (Pdoexception $e) {
Print $e-> getMessage ();
}
}
ReadData ($DBH);
?>