php访问SAP Sybse SQL Anywhere 数据库

环境:

Windows 2008服务器

Apache 2.2 + php 5.3.22


首先

你用 http://localhost/phpinfo.php代码检查一下,php是Thread Safe的吗?php是VC6还是VC9编译的?

如果是VC6编译的,没戏,SAP Sybse SQL Anywhere的Windows版本PHP Module驱动都是VC9编译的。


建议

SQL Anywhere升级到最新补丁


然后

去SAP Sybse SQL Anywhere的PHP Module驱动下载驱动  http://scn.sap.com/docs/DOC-40537

注意:貌似里面的Windows驱动都是VC9(Visual Studio 2010)编译的

注意:驱动分Thread Safe和Single Threaded,




编辑php.ini
extension_dir = "ext"
extension=php-5.3.22_sqlanywhere.dll
;SQL Server 2008 driver

;extension=php_sqlsrv_53_ts.dll
;extension=php_pdo_sqlsrv_53_ts.dll

编写一个测试程序

htdocs\sqla.php

内容如下:

<html> 
<body> 
<p>Record page hits</p> 
<?php  
  $conn = sasql_connect("uid=dba;pwd=sql;ServerName=afariadb;CommLinks=tcpip(host=127.0.0.1;port=2638)"); 
  sasql_query($conn, 
    "CREATE TABLE IF NOT EXISTS hits (hit TIMESTAMP)"); 
  sasql_query($conn, 
    "INSERT INTO hits VALUES(now(*))"); 
  $result = sasql_query($conn, 
    "SELECT TOP 10 hit FROM hits ORDER BY hit DESC"); 
  if ($result) { 
    echo "<table border='1'>\n"; 
    while ($obj = sasql_fetch_object($result)) { 
      echo "<tr>\n"; 
      echo "<td>$obj->hit</td>\n"; 
      echo "</tr>\n"; 
    } 
    sasql_free_result($result); 
    echo "</table>\n"; 
  } 
  sasql_close($conn); 
?>  
</body></html> 


多次运行的结果如下:

Record page hits
2013-12-21 18:07:55.857
2013-12-21 17:24:25.565
2013-12-21 17:24:25.362
2013-12-21 17:24:25.066
2013-12-21 17:24:24.442
2013-12-21 17:24:22.913


=============================

后记:

貌似目前SAP Sybse SQL Anywhere没有相应的PHP PDO驱动

但是你可以用pdo_odbc去访问SAP Sybse SQL Anywhere数据库

参考:http://stackoverflow.com/questions/16473568/codeigniter-sybase-database-configuration



你可能感兴趣的:(php访问SAP Sybse SQL Anywhere 数据库)