PHP pdostatement Objects Bindpram (), Bindvalue (), and Bindcolum

Source: Internet
Author: User
Tags mssql server php database stmt

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

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.

<?php$stm = $pdo->prepare ("SELECT * from users where user =: User"); $user = "Jack";//Correct $stm->bindparam (": User", $ User),//Error $stm->bindparam (": User", "Jack"),//Correct $stm->bindvalue (": User", $user);//Correct $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.?>

The


pdostatement::bindcolumn― binds a column to a PHP variable.

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

<?phpfunction  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  );         /*   through column name binding    */         $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 );? >



Reference Source:
The difference between PHP Pdostatement object Bindpram (), Bindvalue (), and Bindcolumn
Http://www.lai18.com/content/369335.html

Extended Reading

"PHP Database PDO series" series of technical Articles to organize the collection  

1php Database Abstraction Layer PDO

2php Database Abstraction Layer PDO introduction and simple example

3PHP PDO class resolves database connectivity issues

4PHP 5 Data Object (PDO) abstraction layer with Oracle

5PHP Pdostatement:bindparam Insert Data error problem analysis

6PDO Anti-injection principle analysis and considerations for using PDO summary

7PHP Database Abstraction Layer PDO (i)--Introduction and installation Configuration

8PHP Database Abstraction Layer PDO (v)-Error and error handling

9PHP Database Abstraction Layer PDO (iii)--Transaction and Autocommit

10PHP Database Abstraction Layer PDO (ii)--Connection and connection management

11PHP Database Abstraction Layer PDO (four)--preprocessing statements and stored procedures

12PHP Database Abstraction Layer PDO (vii)-related classes and methods

13PHP Database Abstraction Layer PDO (vi)--large object (lobs)

14PHP PDO Operation Summary

15PHP pdostatement The difference between Bindpram (), Bindvalue (), and Bindcolumn

16PDO preprocessing statement Pdostatement Object Usage Summary

Usage and difference of MySQL, mysqli and PDO in 17PHP "original"

18PHP MySQL database operation class for PDO

19php using PDO connection Error connection failed SQLSTATE solution

20php How to connect and query SQL database using PDO

21php connecting the MSSQL Server DB instance with PDO

22php using PDO method

Example of MySQL transaction usage for PDO under 23php

24php using PDO to operate a MySQL DB instance

25PHP PDO Fetch mode output list of various parameters

26 a summary of some knowledge about PHP PDO

Database connection mode in 27php comparison of PDO and mysqli

28PDO Anti-injection principle analysis and precautions

29php MySQL Connection method PDO use detailed

30PHP using PDO to connect to an Access database

31php the PDO way realizes the database to delete and change to investigate

32 on the ROWCOUNT function of PDO

PHP pdostatement Objects Bindpram (), Bindvalue (), and Bindcolum

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.