Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

sqlsrv_fetch(3) [php man page]

SQLSRV_FETCH(3) 														   SQLSRV_FETCH(3)

sqlsrv_fetch - Makes the next row in a result set available for reading

SYNOPSIS
mixed sqlsrv_fetch (resource $stmt, [int $row], [int $offset]) DESCRIPTION
Makes the next row in a result set available for reading. Use sqlsrv_get_field(3) to read the fields of the row. PARAMETERS
o $stmt - A statement resource created by executing sqlsrv_query(3) or sqlsrv_execute(3). o $row - The row to be accessed. This parameter can only be used if the specified statement was prepared with a scrollable cursor. In that case, this parameter can take on one of the following values: oSQLSRV_SCROLL_NEXT oSQLSRV_SCROLL_PRIOR oSQLSRV_SCROLL_FIRST oSQLSRV_SCROLL_LAST oSQLSRV_SCROLL_ABSOLUTE oSQLSRV_SCROLL_RELATIVE o $offset - Specifies the row to be accessed if the row parameter is set to SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVE. Note that the first row in a result set has index 0. RETURN VALUES
Returns TRUE if the next row of a result set was successfully retrieved, FALSE if an error occurs, and NULL if there are no more rows in the result set. EXAMPLES
Example #1 sqlsrv_fetch(3) example The following example demonstrates how to retrieve a row with sqlsrv_fetch(3) and get the row fields with sqlsrv_get_field(3). <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT Name, Comment FROM Table_1 WHERE ReviewID=1"; $stmt = sqlsrv_query( $conn, $sql); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } // Make the first (and in this case, only) row of the result set available for reading. if( sqlsrv_fetch( $stmt ) === false) { die( print_r( sqlsrv_errors(), true)); } // Get the row fields. Field indeces start at 0 and must be retrieved in order. // Retrieving row fields by name is not supported by sqlsrv_get_field. $name = sqlsrv_get_field( $stmt, 0); echo "$name: "; $comment = sqlsrv_get_field( $stmt, 1); echo $comment; ?> SEE ALSO
sqlsrv_get_field(3), sqlsrv_fetch_array(3), sqlsrv_fetch_object(3). PHP Documentation Group SQLSRV_FETCH(3)

Check Out this Related Man Page

SQLSRV_EXECUTE(3)														 SQLSRV_EXECUTE(3)

sqlsrv_execute - Executes a statement prepared withsqlsrv_prepare(3)

SYNOPSIS
bool sqlsrv_execute (resource $stmt) DESCRIPTION
Executes a statement prepared with sqlsrv_prepare(3). This function is ideal for executing a prepared statement multiple times with dif- ferent parameter values. PARAMETERS
o $stmt - A statement resource returned by sqlsrv_prepare(3). RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 sqlsrv_execute(3) example This example demonstrates how to prepare a statement with sqlsrv_prepare(3) and re-execute it multiple times (with different param- eter values) using sqlsrv_execute(3). <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false) { die( print_r( sqlsrv_errors(), true)); } $sql = "UPDATE Table_1 SET OrderQty = ? WHERE SalesOrderID = ?"; // Initialize parameters and prepare the statement. // Variables $qty and $id are bound to the statement, $stmt. $qty = 0; $id = 0; $stmt = sqlsrv_prepare( $conn, $sql, array( &$qty, &$id)); if( !$stmt ) { die( print_r( sqlsrv_errors(), true)); } // Set up the SalesOrderDetailID and OrderQty information. // This array maps the order ID to order quantity in key=>value pairs. $orders = array( 1=>10, 2=>20, 3=>30); // Execute the statement for each order. foreach( $orders as $id => $qty) { // Because $id and $qty are bound to $stmt1, their updated // values are used with each execution of the statement. if( sqlsrv_execute( $stmt ) === false ) { die( print_r( sqlsrv_errors(), true)); } } ?> NOTES
When you prepare a statement that uses variables as parameters, the variables are bound to the statement. This means that if you update the values of the variables, the next time you execute the statement it will run with updated parameter values. For statements that you plan to execute only once, use sqlsrv_query(3). SEE ALSO
sqlsrv_prepare(3), sqlsrv_query(3). PHP Documentation Group SQLSRV_EXECUTE(3)
Man Page