Linux with SQL Server 2012 and the PHP server extension enabled

Source: Internet
Author: User
Tags mssql php server stmt zts

Connecting to a SQL Server 2012 database
Http://www.freetds.org/userguide/choosingtdsprotocol.htm

Download and install ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.20.tar.gz
./configure--prefix=/usr/local/freetds--with-tdsver=7.4--enable-msdblib
Make && make install
Verifying version/usr/local/freetds/bin/tsql-c

Connecting to a SQL Server 2012 database
/usr/local/freetds/bin/tsql-h 192.168.1.200-p 1433-u username-p Password

Installation and expansion
Mssql
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--with-mssql=/usr/local/freetds
Make && make install

Pdo_dblib
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--with-pdo-dblib=/usr/local/freetds
Make && make install

Extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/pdo_dblib.so
Extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/mssql.so

Test testsqldb.php after reboot
MSSQL mode

<?phpheader("Content-type: text/html; charset=utf-8");//$msdb=mssql_connect("数据库IP","用户名","密码");   $msdb=mssql_connect("192.168.1.200:1433","username","password");if (!$msdb) {    echo "connect sqlserver error";    exit;    }mssql_select_db("SCCMdata",$msdb);$result = mssql_query("select * from Agents", $msdb);while($row = mssql_fetch_array($result)) { print_r($row);}mssql_free_result($result);?>

Pdo_dblib Way

<?phpheader("Content-type: text/html; charset=utf-8");  try {    $hostname = "192.168.1.200";    $port = 1433;    $dbname = "SCCMdata";    $username = "username";    $pw = "password";    $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");  } catch (PDOException $e) {    echo "Failed to get DB handle: " . $e->getMessage() . "\n";    exit;  }  $stmt = $dbh->prepare("select * from Agents");  $stmt->execute();  while ($row = $stmt->fetch()) {    print_r($row);  }  unset($dbh); unset($stmt);?>

Linux with SQL Server 2012 and the PHP server extension enabled

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.