Microsoft Drivers for PHP for SQL Server 2.0

Leave a comment (0) Go to comments

Microsoft has released of the Microsoft Drivers for PHP for SQL Server 2.0, today (05-August-2010).

The major highlight of this release is the addition of the PDO_SQLSRV driver, which adds support for PHP Data Objects (PDO), which removes data access complexity in PHP applications.

Architecture – “Microsoft Drivers for PHP for SQL Server 2.0”

While the major focus of this release was the PDO_SQLSRV driver, Microsoft took this as an opportunity to re-architect our code create a core functional layer so that we can offer the same functionality and consistency in both drivers (SQLSRV and PDO_SQLSRV). This new architecture enables us to add new features easily to both drivers.

Microsoft Drivers for PHP for SQL Server 2.0 sql server php connection string php sql server connection example code php sql server php script connect sql server php ms sql 2008 connection string php db ms sql 2008 connection string php connection string for sql server php Connect to sql server using DSN connection php code to connect sql server PHP Code to access SQL SERVER 2008 PHP Code sql server Microsoft Drivers for PHP for SQL Server how to connect to sql server using php

PHP developers are now free to select the driver of their choice, using either the native SQLSRV API (SQLSRV driver) or the PDO API (PDO_SQLSRV driver) for accessing SQL Server or SQL Azure. The following code snippets provide an illustration of a simple task (query and list products from AdventureWorks sample database) using each driver:

SQLSRV driver (Example):


<?php
$serverName = “(local)\sqlexpress”;
$connectionOptions = array( “Database”=>”AdventureWorks” );

/* Connect to SQL Server using Windows Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionOptions );

/* Get products by querying against the product name.*/
$tsql = “SELECT ProductID, Name, Color, Size, ListPrice FROM Production.Product”;

/* Execute the query. */
$getProducts = sqlsrv_query( $conn, $tsql );

/* Loop thru recordset and display each record. */
while( $row = sqlsrv_fetch_array( $getProducts, SQLSRV_FETCH_ASSOC ) )
{
print_r( $row );
}

/* Free the statement and connection resources. */
sqlsrv_free_stmt( $getProducts );
sqlsrv_close( $conn );
?>

PDO_SQLSRV driver (Example):

<?php
$serverName = “(local)\sqlexpress”;

/* Connect to SQL Server using Windows Authentication. */
$conn = new PDO( “sqlsrv:server=$serverName; Database=AdventureWorks” );

/* Get products by querying against the product name.*/
$tsql = “SELECT ProductID, Name, Color, Size, ListPrice FROM Production.Product”;

/* Execute the query. */
$getProducts = $conn->query( $tsql );

/* Loop thru recordset and display each record. */
while( $row = $getProducts->fetch( PDO::FETCH_ASSOC ) )
{
print_r( $row );
}

/* Free the statement and connection resources. */
$getProducts = NULL;
$conn = NULL;
?>

Other Information

Download Microsoft Drivers for PHP for SQL Server 2.0

SQL Server Driver for PHP Documentation

Refer the Post “PHP Code to access SQL SERVER 2008” to learn How to access SQL Server using PHP.

EOF - Microsoft Drivers for PHP for SQL Server 2.0, SQL Server 2012 , 2008 R2 , 2008 , 2005 , 2000

Leave a Reply

Your email address will not be published. Required fields are marked *


*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.