title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic |
---|---|---|---|---|---|---|---|
PDOStatement::bindColumn |
API reference for the PDOStatement::bindColumn function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server. |
David-Engel |
davidengel |
08/10/2020 |
sql |
connectivity |
reference |
[!INCLUDEDriver_PHP_Download]
Binds a variable to a column in a result set.
bool PDOStatement::bindColumn($column, &$param[, $type[, $maxLen[, $driverdata ]]] );
$column: The (mixed) number of the column (1-based index) or name of the column in the result set.
&$param: The (mixed) name of the PHP variable to which the column will be bound.
$type: The optional data type of the parameter, represented by a PDO::PARAM_* constant.
$maxLen: Optional integer, not used by the Microsoft Drivers for PHP for SQL Server.
$driverdata: Optional mixed parameter(s) for the driver. For example, you could specify PDO::SQLSRV_ENCODING_UTF8 to bind the column to a variable as a string encoded in UTF-8.
TRUE if success, otherwise FALSE.
Support for PDO was added in version 2.0 of the [!INCLUDEssDriverPHP].
This example shows how a variable can be bound to a column in a result set.
<?php
$database = "AdventureWorks";
$server = "(local)";
$conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");
$query = "SELECT Title, FirstName, EmailAddress FROM Person.Contact where LastName = 'Estes'";
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('EmailAddress', $email);
while ( $row = $stmt->fetch( PDO::FETCH_BOUND ) ){
echo "$email\n";
}
?>