sqlsrv_query
sqlsrv_query
Prepares and executes a query
mixed **sqlsrv_query** resource $conn string $sql array $params array $options
Prepares and executes a query.
conn
A connection resource returned by .
sqlsrv_connect
sqlThe string that defines the query to be prepared and executed.
paramsAn array specifying parameter information when executing a parameterized query.
Array elements can be any of the following:
The following table describes the elements in the array structure above:
optionsAn array specifying query property options. The supported keys are described
in the following table:
Returns a statement resource on success and false if an error occurred.
Voorbeeld: example
<?php
$serverName = "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
$sql = "INSERT INTO Table_1 (id, data) VALUES (?, ?)";
$params = array(1, "some data");
$stmt = sqlsrv_query( $conn, $sql, $params);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
?>
For statements that you plan to execute only once, use .
If you intend to re-execute a statement with different parameter values, use
the combination of and .
sqlsrv_query``sqlsrv_prepare``sqlsrv_execute
sqlsrv_prepare``sqlsrv_execute