The example in this article describes the workaround for php5.3 not being able to connect to the MSSQL database. Share to everyone for your reference. The specific analysis is as follows:
Since php5.3 after the system does not support mssql_connect This function is connected, I used to talk about the use of COM interface to implement, and now I would like to introduce the solution php5.3 can not connect the MSSQL database another method.
Under Windows System, the PHP5.3 version already does not support MSSQL extensions.
First http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx click get it download SQLSRV20.EXE.
Unzip the file into PHP's extended folder ext, open php.ini at the end add:
Copy Code code as follows:
[Php_pdo_sqlsrv]
Extension=php_pdo_sqlsrv_53_nts_vc6.dll
[Php_sqlsrv]
Extension=php_sqlsrv_53_nts_vc6.dll
After saving to restart Apache, attach a simple PHP connection example, the code is as follows:
Copy Code code as follows:
<?php
$serverName = "(127.0.0.1)";
$connectionInfo = Array ("UID" => "root",
"PWD" => "root2010",
"Database" => "master");
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if ($conn)
{
echo "Connection ESTABLISHED.N";
}
Else
{
echo "Connection could not to be ESTABLISHED.N";
Die (Print_r (Sqlsrv_errors (), true));
}
?>
I am using the wamp5.1 integrated installation package, the tests done on Windows Server 2008, php5.4 the above version test was unsuccessful.
If you are using this extension to connect to SQL Server version 2005, such as SQL Server 2008, you will need to install SQL Server Native on the machine first client:http:// Download.microsoft.com/download/0/e/6/0e67502a-22b4-4c47-92d3-0d223f117190/sqlncli.msi
This extension provides PHP with a new set of functions that begin with a series of sqlsrv_ functions, as follows:
Copy Code code as follows:
Sqlsrv_begin_transaction
Sqlsrv_cancel
Sqlsrv_client_info
Sqlsrv_close
Sqlsrv_commit
Sqlsrv_configure
Sqlsrv_connect
Sqlsrv_errors
Sqlsrv_execute
Sqlsrv_fetch
Sqlsrv_fetch_array
Sqlsrv_fetch_object
Sqlsrv_fetch_metadata
Sqlsrv_free_stmt
Sqlsrv_get_config
Sqlsrv_get_field
Sqlsrv_has_rows
Sqlsrv_next_result
Sqlsrv_num_fields
Sqlsrv_num_rows
Sqlsrv_prepare
Sqlsrv_query
Sqlsrv_rollback
sqlsrv_rows_affected
Sqlsrv_send_stream_data
Sqlsrv_server_info
More detailed instructions can be found in the self-extracting file just now in a Sqlserverdriverforphp.chm help file can find the open Click API Reference node.
See also a ODB connection way, the code is as follows:
Copy Code code as follows:
$dbhost = ';
$dbuser = '; Name of your MSSQL user
$dbpass = '; Your MSSQL code.
$dbname = '; The name of your MSSQL library
$connect =odbc_connect ("Driver={sql Server}"; server= $dbhost;D atabase= $dbname "," $dbuser "," $dbpass ");
$sql = "SELECT * from Content";
$exec =odbc_exec ($connect, $sql);
while ($row = (Odbc_fetch_array ($exec)))
{
$row [' ID ']//? Take field values
...
}
I hope this article will help you with your PHP program design.