PHP extension mssql.so Connection sqlserver2008

Source: Internet
Author: User

1. Installation Configuration FreeTDS

wget http://tar zxf freetds_0.  the . orig.tar.gz cd freetds_0.  the  . /configure--prefix=/usr/local/freetds--with-tdsver=8.0 -–enable-msdblib-–enable-dbmfix-–with-gnu-ld- enable-shared-–enable-Static

2. Compiling the MSSQL module of PHP

cd/path/to/php/source enters the PHP source directory CD ext//usr/local/webserver/php/bin/phpize generates the compilation configuration file. /configure–with-php-config=/usr/local/webserver/php/bin/php-config–with-mssql=/usr/local/


Compile to build mssql.so, modify php.ini, load the module into:
extension= "/path/to/extension/mssql.so"

3. Configure MSSQL

cd/usr/local/freetds/etc Edit file: vi freetds.conf [Global] # TDS protocol version; TDS version=4.2# Whether to write a tdsdump file forDiagnostic purposes # (setting ThisTo/tmp isInsecure on a multi-user system); Dump file=/tmp/freetds.log; Debug Flags=0xFFFF# Command and connection timeouts; timeout=Ten; Connect Timeout=Ten# If YouGet  out-of-memory errors, it may mean that your client # isTrying to allocate a huge buffer fora text field. # Try setting ' text Size'To a more reasonable limitText size =64512Client CharSet= utf-8#加入 #加入 [Server2005] host=192.168. x.x Port=1433TDS Version=7.2 

4. Test TDS

./tsql-s 192.168.0.109-u User name-p password-d database
If you can see 1> the connection is successful

5. Test PHP Connection MSSQL

Copy CodeThe code is as follows:
<?php
try {
$hostname = ' 218.x.x.x ';//note, this is different from the above, to use the IP address or host name directly
$port =1433;//Port
$dbname = "user";//Library name
$username = "database";//user
$PW = "passwd";//Password
$DBH = new PDO ("dblib:host= $hostname: $port;d bname= $dbname", "$username", "$PW");
} catch (Pdoexception $e) {
echo "Failed to get DB handle:". $e->getmessage (). " n ";
Exit
}
Echo ' connent MSSQL succeed ';
$stmt = $dbh->prepare ("SELECT * from Z_2010pinjiu_user");
$stmt->execute ();
while ($row = $stmt->fetch ()) {
Print_r ($row);
}
Unset ($DBH); Unset ($stmt);
?>

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.