Skip to content

Latest commit

 

History

History
73 lines (53 loc) · 2.64 KB

pdostatement-execute.md

File metadata and controls

73 lines (53 loc) · 2.64 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic
PDOStatement::execute
API reference for the PDOStatement::execute function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server.
David-Engel
davidengel
08/10/2020
sql
connectivity
reference

PDOStatement::execute

[!INCLUDEDriver_PHP_Download]

Executes a statement.

Syntax

  
bool PDOStatement::execute ([ $input ] );  

Parameters

$input: (Optional) An associative array containing the values for parameter markers.

Return Value

true on success, false otherwise.

Remarks

Statements executed with PDOStatement::execute must first be prepared with PDO::prepare. See Direct Statement Execution and Prepared Statement Execution in the PDO_SQLSRV Driver for information on how to specify direct or prepared statement execution.

All values of the input parameters array are treated as PDO::PARAM_STR values.

If the prepared statement includes parameter markers, you must either call PDOStatement::bindParam to bind the PHP variables to the parameter markers or pass an array of input-only parameter values.

Support for PDO was added in version 2.0 of the [!INCLUDEssDriverPHP].

Example

<?php  
$database = "AdventureWorks";  
$server = "(local)";  
$conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");  
  
$query = "select * from Person.ContactType";  
$stmt = $conn->prepare( $query );  
$stmt->execute();  
  
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){  
   print "$row[Name]\n";  
}  
  
echo "\n";  
$param = "Owner";  
$query = "select * from Person.ContactType where name = ?";  
$stmt = $conn->prepare( $query );  
$stmt->execute(array($param));  
  
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){  
   print "$row[Name]\n";  
}  
?>  

Note

It is recommended to use strings as inputs when binding values to a decimal or numeric column to ensure precision and accuracy as PHP has limited precision for floating point numbers. The same applies to bigint columns, especially when the values are outside the range of an integer.

See Also

PDOStatement Class

PDO