Have you got the following code in which they are demonstrating the connection and retrieval data using PHP from an MS SQL DB
Code:
<?php
/*Connect to the local server using Windows authentication and specify
the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array( "Database"=>"AdventureWorks");
if( !($conn = sqlsrv_connect( $serverName, $connectionInfo)))
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Set up the T-SQL query. */
$tsql = "SELECT ReviewerName,
ReviewDate,
Rating,
Comments
FROM Production.ProductReview
WHERE ProductID = ?
ORDER BY ReviewDate DESC";
/* Set the parameter value. */
$productID = 709;
$params = array( $productID);
/* Execute the query. */
if( !($stmt = sqlsrv_query($conn, $tsql, $params)))
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Retrieve and display the data. The first and third fields are
retrieved according to their default types, strings. The second field
is retrieved as a string with 8-bit character encoding. The fourth
field is retrieved as a stream with 8-bit character encoding.*/
while ( sqlsrv_fetch( $stmt))
{
echo "Name: ".sqlsrv_get_field( $stmt, 1 )."\n";
echo "Date: ".sqlsrv_get_field( $stmt, 2,
SQLSRV_PHPTYPE_STRING( SQLSRV_ENC_CHAR))."\n";
echo "Rating: ".sqlsrv_get_field( $stmt, 3 )."\n";
echo "Comments: ";
$comments = sqlsrv_get_field( $stmt, 4,
SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
fpassthru( $comments);
echo "\n";
}
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
Bookmarks