Download php architect: May 2009

Transcript
FEATURE
Getting Started with the SQL Server Driver for PHP
5.2.4. We are working with the community to make sure
the extension also works well in 5.3.x environments.
To install the driver, download the driver package from
the Microsoft Download Center (http://go.microsoft.
com/fwlink/?LinkId=123470) and run the self-extracting
.exe. The self-extracting .exe contains two .dll files:
php_sqlsrv.dll (non-thread-safe) and php_sqlsrv_ts.dll
(thread-safe). Place the appropriate .dll file in the PHP
extension directory (such as C:\PHP\ext). Developers
"
packs, which ensures that the SQL Server Driver for PHP
will be able to provide support for future SQL Server releases without requiring major re-writes to the driver’s
code. This approach allows the SQL Server Driver for
PHP to leverage existing features in the current ODBC
driver (such as connection pooling) and easily make future SQL Server features (such as new data types) available to the PHP community in a timely fashion.
While the initial release of the SQL Server Driver for
The SQL Server Driver for PHP supports all editions
of both SQL Server 2005 and 2008, from Express to
Enterprise, including support for all new SQL Server
2008 data types.
working with a non-thread-safe build of PHP (php5.dll)
should use the non-thread-safe version of the driver
while developers working with a thread-safe build of
PHP (php5ts.dll) should use the thread-safe version
of the driver. Note: Guidance on PHP on the IIS site
(http://www.iis.net/php) recommends using the nonthread-safe version of PHP for performance and security
reasons.
Once you’ve copied the appropriate build of the
driver in the PHP extension directory, edit the php.ini
file to tell the PHP engine to load the driver assembly.
Developers working with the non-thread-safe version
of the driver should add the following entry to the
Dynamics Extension section: extension=php_sqlsrv.dll
Developers working with the thread-safe version of the driver should add the following instead:
extension=php_sqlsrv_ts.dll
Additional Required Components
The SQL Server Driver for PHP does not communicate
directly with SQL Server. Instead, the driver relies on
the Microsoft SQL Server Native Client ODBC Driver to
handle the communication with SQL Server. The SQL
Server Driver for PHP is essentially a very thin layer
atop the ODBC driver. You can download the ODBC
driver here: http://msdn.microsoft.com/en-us/library/
cc296170(SQL.90).aspx.
Microsoft continues to provide an updated ODBC
driver for each release of SQL Server, including service
38 | May 2009 www.phparch.com
PHP is built on top of the ODBC driver written for SQL
Server 2005, the SQL Server Driver for PHP supports SQL
Server 2008 as well, including all new SQL Server 2008
data types.
Microsoft also recently demonstrated its continued
commitment to ODBC through the introduction of a new
version of ODBC (3.8) with the recent Windows 7 beta.
For developers building new applications in C or C++,
ODBC is still the most powerful, stable and best-performing technology for communicating with SQL Server.
In short, building the SQL Server Driver for PHP on
top of the ODBC driver gives PHP developers a highly
performant solution for SQL Server connectivity, for
both current and future versions of SQL Server.
Connecting to Your SQL Server Database
Connecting to your SQL Server Database using the SQL
Server Driver for PHP is easy. To open a connection,
simply call the sqlsrv_connect function and specify
the name of the desired server. An instance name
(ServerName\InstanceName) can be supplied if you’re
trying to connect to a named instance of SQL Server. If
you want to talk to an instance of SQL Server running
on the same machine as your PHP code, you can specify
either ’(local)’ or ’.’ as the server name. For example,
the following line of code establishes a connection to
the local machine.
$conn = sqlsrv_connect('.\SQLExpress');