PHP connection to MS SQL Server under Linux

Source: Internet
Author: User
Tags sybase

PHP connection to MS SQL Server under Linux
Analyze problems
PHP scripts Read and write SQL Server is not a problem, in Apache for Windows and Windows IIS can work very well, generally can be connected via ODBC or SQL Server client, which is available under Windows. But there is no existing ODBC and SQL Server Client under Linux, and we need to install it ourselves.

Solve the problem

First, related software
Freetds-0.53.tgz
This software can connect MS SQL Server and Sybase databases with Linux and UNIX.

Second, installation configuration steps

First step: Compile and install FreeTDS:
After getting freetds-0.53.tgz
CP freetds-0.53.tgz/tmp/. (Copy FreeTDS package to/tmp directory)
Cd/tmp (Enter directory)
Tar zxvf freetds-0.53.tgz (unzip)
CD freetds-0.53 (enter the extracted directory)
./configure–prefix=/usr/local/freetds--with-tdsver=7.0
Gmake (Generate makefile, I've tried, make can also)
Gmake Install (Installation)
About the above configure I would like to say,--prefix=/usr/local/freetds refers to the installation of/usr/local/freetds this directory,--with-tdsver=7.0 refers to the installation of TDS Version 7.0 (most open I did not add this compilation parameter, the result is compiled by default to 5.0.) 5.0 the port to connect to the database is 4000, not SQL Server 1433)

Step Two: Recompile PHP4
./configure [--with-apxs--with-mysql ...]--with-sybase=/usr/local/freetds (please note that Sybase)
Make
Make install
Step Three: Configure FreeTDS
Vi/usr/local/freetds/etc/freetds.conf
See instructions in this file for specific configuration
Example: (Typical configuration)
[SQL Server]
Host = SQL_SERVER_NAME_OR_HOST_IP (your SQL Server machine name or IP address)
Port = 1433
TDS Version = 7.0
In this configuration file can be configured Windows domain login or SQL Server account login two ways

Fourth step: Configure the php.ini file
to find; extension=mssql70.so.
Take notes;
Extension=mssql70.so

Fifth step: Establishing a database connection in PHP
$link =mssql_connect ("SQL Server", $your _username, $your _password) or Die ("can ' t connect to Database");
Echo $link;
Run the above script in the browser, if you get a link number then congratulations, you've already configured, if it appears call to undefined function:mssql_connect () That means look closely at the installation configuration process to see which step you are not right.
Note: The SQL Server name is the host parameter defined in/usr/local/freetds/etc/freetds.conf, if you write an IP address, it is the IP address.
Other database operations reference related MSSQL functions
Note that the Chinese!!! is not supported in SQL statements

Sixth step: Commissioning
If you cannot connect, locate it in the FreeTDS configuration file, dump file =/tmp/freetds.log, comment out the previous semicolon, and then execute the test script to see/tmp/ Freetds.log file, it can tell you a lot of error information to help you troubleshoot problems.

PHP Connection to Oracle Database
PHP provides two sets of functions to connect with Oracle, namely the Ora_ and OCI functions. Where the Ora_ function is slightly stale. The OCI function update is said to be better. The use of the two grammars is almost the same. As mentioned earlier, your PHP installation options should be able to support the use of both.
Connection

if ($conn =ora_logon ("[Email protected]", "password"))
{
echo "SUCCESS! Connected to database\n ";
}
Else
{
echo "Failed:-( Could not connect to database\n ";
}
Ora_logoff ($conn);
Phpinfo ();
?>

The above code connects to the database using the Oracle database name, user name, and password defined by Tnsname (indicated in your Tnsnames.ora file). On the basis of a successful connection, the Ora_logon function returns a nonzero connection ID and stores it in the variable $conn.
Detailed content
http://hi.baidu.com/Universal Network/blog/item/3fe4df12c474e9956438db72.html

PHP connection to MS SQL Server under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.