Catalogue [-]
- How to install mssql.so
- How to install Pdo_lib. So
- How to install PDO_ODBC. So
Author: Roban Lee ([email protected])
There are many ways to connect MSSQL using PHP under Linux, depending on the environment, you can choose different ways, roughly the following methods:
- Using mssql.so extensions
- Using Pdo_lib extensions
- Using PDO_ODBC extensions
How to install mssql.so
1. MSSQL. So extension relies on an external package, namely FreeTDS, FreeTDS official website: http://www.freetds.org. After downloading the latest installation package from the official website, install (Specify a directory) by executing the following command:
?
1 |
. /configure --prefix= /usr/local/freetds |
2. Configure FreeTDS
Open the freetds.conf in the FreeTDS ECT directory, and add the following at the end of the file:
?
1234 |
[testServer] host = 192.168.x.x #你的SQL SERVER IP port = 1433 #SQL SERVER PORT tds version = 7.0 |
3. Go to the Ext directory in the PHP source directory, find the MSSQL directory, compile the extension
?
1 |
. /configure --with-php-config= /usr/local/php/bin/php-config --with-mssql= /usr/local/freetds |
4. After the installation is complete, execute the following command to add the extension to the PHP configuration file
?
1 |
echo extension=mssql.so >> PHP_INSTALL_PATH /lib/php .ini |
5. See if the extension is already loaded.
?
6. Write a script to test for normal loading (Mssql_connect the first parameter is the server name in the FreeTDS you just configured)
?
123 |
<?php mssql_connect( ‘testServer‘ , ‘SQL SIGNIN ACCOUNT‘ , ‘PASSWORD‘ ) OR DIE ( ‘cannot connect msserver‘ ) |
7. Done
How to install Pdo_lib. so
Pdo_lib installation method and dependent package basic and MSSQL the same, the only difference is the compile time parameters, enter the Pdo_lib expansion package, the installation time parameter input:
?
1 |
. /configure --with-php-config= /usr/local/php/bin/php-config --with-pdo-dblib= /usr/local/freetds |
After the installation is complete, add pdo_lib.so to the configuration file and then write the test file:
?
1234 |
<?php $dbh = new PDO( "dblib:host=testServer;dbname=db" , "test" , "test" ); var_dump( $dbh ); |
How to install PDO_ODBC. sopdo_odbc This extension is slightly different from the above 2 extensions, depending on 2 packages, one FreeTDS, the other is UNIXODBC, there are some differences in the installation method, the first is the need to install UNIXODBC (: http://www.unixodbc.org/)
After download, install directly after installation, you need to add a configuration, in the UNIXODBC/ETC directory to add the following configuration:
?
1234567 |
[testDSN] Driver = /usr/local/freetds/lib/libtdsodbc .so Description = First Test DSN Trace = No Servername = testServer # 这个就是FREETDS里面配置的服务器信息 Database = test UID = test |
Next is the installation of FREETDS requires an additional parameter:
?
1 |
. /configure --prefix= /usr/local/freetds --with-unixodbc= /usr/local/unixODBC |
After installing FreeTDS, go to the extension directory to install the extension:
?
1 |
. /configure --with-php-config= /usr/local/php/bin/php-config --with-pdo-odbc=unixODBC, /usr/local/unixODBC |
After the installation is complete, write a script to test the connection:
?
123456 |
<?php $dbh = new PDO( ‘odbc:testDSN‘ , ‘test‘ , ‘test‘ ); var_dump( $dbh ); |
All is done.
Good LUCK,
How to connect MSSQL using PHP under Linux