The difference between PHP Pdostatement object Bindpram (), Bindvalue (), and Bindcolumn, pdostatement_php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.