Since php5.3 and later, the system does not support mssql_connect function connection. in the past, I also talked about using the com interface. now I will introduce another method to solve the problem that php5.3 cannot connect to the mssql database. in windows ,... since php5.3 and later, the system does not support mssql_connect function connection. in the past, I also talked about using the com interface. now I will introduce another method to solve the problem that php5.3 cannot connect to the mssql database.
In windows, versions later than PHP5.3 do not support mssql extension.
First http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx click get it to download SQLSRV20.EXE.
Decompress the file to ext, the extension folder of php, and open php. ini and add it at the end:
[PHP_PDO_SQLSRV]
Extension = php_pdo_sqlsrv_53_nts_vc6.dll
[PHP_SQLSRV]
Extension = php_sqlsrv_53_nts_vc6.dll
After saving the file, restart apache and attach a simple php connection example. the code is as follows:
"Root", "PWD" => "root2010", "Database" => "master"); $ conn = sqlsrv_connect ($ serverName, $ connectionInfo ); // open source code phprm. comif ($ conn) {echo "Connection established. n ";} else {echo" Connection cocould not be established. n "; die (print_r (sqlsrv_errors (), true ));}
I am using the wamp5.1 integrated installation package. I did a test on windows server 2008 and php5.4 or above, but the test was not successful.
If you use this extension to connect to SQL server 2005 or a later version of SQL server (such as SQL server 2008), you also need to first install SQL Server Native Client: http://download.microsoft.com/download/0/E/6/0E67502A-22B4-4C47-92D3-0D223F117190/sqlncli.msi on the machine
This extension adds a series of functions starting with sqlsrv _ to php. the Function reference is 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
For more details, you can find the SQLServerDriverForPHP. chm help file in the self-extracting file and click the API Reference node.
In addition, the code for reading an odb connection method is as follows:
$ Dbhost = "; $ dbuser ="; // your mssql username $ dbpass = "; // your mssql password $ dbname = "; // your mssql Database name $ connect = odbc_connect ("Driver = {SQL Server}; Server = $ dbhost; Database = $ dbname", "$ dbuser ", "$ dbpass"); $ SQL = "select * from content"; $ exec = odbc_exec ($ connect, $ SQL ); while ($ row = (odbc_fetch_array ($ exec) {$ row ['id'] //? Field value... }