Home >Backend Development >PHP Tutorial >PHP connection to MSSQL and errors during use_PHP tutorial
Environment PHP5.2.6
SQL2005 Standard Edition
SERVER2003 SP2
1: The SQL2005 file is damaged and cannot be used normally. Then, it is not completely uninstalled. Result: Reinstall the system, which is convenient and fast.
2: There are some minor problems with PHP configuration to support MSSQL. The mssql_connect connection method cannot be connected. You can only use ODBC to connect
Solution: Add NTWDBLIB.DLL to SYSTEM32. PHP comes with connection 7.0 and is invalid for 2005
It is said that this DLL can be found in the SQL installation file - -!
Attached are the codes for the two connection methods:
//mssql_connect connection method
//Server and login Info
$SERVER = 'IP';
$USER_NAME = "USER";
$USER_PASS = "PASS";
$DATABASE = "DBNAME";
//Connecting to the server
$CONN = mssql_connect($SERVER, $USER_NAME, $USER_PASS)or die ("Can't connect to Microsoft SQL Server");
//Selecting the database
$connection = mssql_select_db($DATABASE, $CONN)or die ("Can't connect to Database");
if($connection) printf ("Connected successfully");
?>
//ODBC connection method
$connection_string = 'DRIVER={SQL Server};SERVER=IP;DATABASE=DBNAME';
$user = 'USER';
$pass = 'PASS';
$connection = odbc_connect( $connection_string, $user, $pass ) OR die("??");
if($connection) printf ("Connected successfully");
?>
Author "Growth Footprints"