Home > Article > Backend Development > SQL Server database created on Navicat premium, realize connection using PHP (that is, php connects to Microsoft MSSQL), navicatpremium_PHP tutorial
can be used in Sybase’s db-lib or The ct-lib library also contains an ODBC library. Allows many applications to connect to Sybase or Microsoft SQL servers;
Use FreeTDS under windows
What is FreeTDS? FreeTDS is actually an open source (or can be said to be free) C program library, which can access and operate Microsoft's SQL database under the Linux system. FreeTDS is released as source code, and because of this, it can be compiled and installed on almost any system.
If your server is a Windows system, then you should use php_dblib.dll. (more information on Using FreeTDS for Unix.)
1: Follow the link below to download php_dblib.dll and save it to the /PHP/ext folder.
https://docs.moodle.org/30/en/Installing_MSSQL_for_PHP#Using_the_SQL_Server_2005_Driver_for_PHP_from_Microsoft_on_Windows
2. Add:
to the php configuration file /PHP/php.iniextension=php_dblib.dll Restart apache
3:Test:
1 <?<span>php </span>2 <span>$link</span> = mssql_connect('localhost', 'db_user', 'db_password'<span>); </span>3 <span>if</span>(!<span>$link</span><span>) { </span>4 <span>echo</span>'Could not connect'<span>; </span>5 <span>die</span>('Could not connect: ' .<span> mssql_error()); </span>6<span> } </span>7 <span>echo</span>'Successful connection'<span>; </span>8 mssql_close(<span>$link</span><span>); </span>9 ?>
ok, success!!!
Reference: http://www.th7.cn/Program/php/201303/129462.shtml