关闭

php osx php pdo连接mssql方法

标签: php pdo mssql
332人阅读 评论(0) 收藏 举报
分类:

autoconf

autoconf-latest.tar.gz

$./configure
$make
$sudo make install

freetds


FreeTDS: freetds-stable.tgz.

$./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --sysconfdir=/usr/local/freetds/conf
$make
$sudo make install

php源码

下载与安装版本对应版本的源码php-5.4.17.tar.bz2 from Apple

mssql.so

$phpize
$./configure --with-php-config=/usr/bin/php-config --with-mssql=/usr/local/freetds/
$make
$sudo cp modules/mssql.so /usr/lib/php/extensions/no-debug-non-zts-20100525/

pdo_dblib.so

<pre name="code" class="plain" style="color: rgb(43, 43, 43); font-size: 16px; line-height: 24px;"><pre name="code" class="plain">$phpize
$./configure --with-php-config=/usr/bin/php-config --with-pdo-dblib=/usr/local/freetds/
$make
$sudo cp modules/pdo_dblib.so /usr/lib/php/extensions/no-debug-non-zts-20100525/





编辑php.ini

$sudo vim /etc/php.ini
添加如下语句

  • extension=mssql.so
  • extension=pdo_dblib.so

重启apache

$sudo /usr/sbin/apachectl restart
至此安装完成

配置freetds.conf

$sudo vim /usr/local/freetds/conf/freetds.conf
<span style="font-family:monospace, serif;">[global]
        # TDS protocol version
;       tds version = 4.2

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.  
        # Try setting 'text size' to a more reasonable limit 
        text size = 64512

# Define a connection to the MSSQL server.
[host别名]
        host = 192.168.3.100
        port = 1433
        tds version = 8.0</span>

示例代码

        try {
            $dbh = new PDO("dblib:host=$dbhost;dbname=$dbname", "$dbuser","$dbpwd"););
            echo '成功';
        } catch (PDOException $e) {
            echo 'Connection failed: ' . $e->getMessage();
        }
其中$dbhost是freetds.conf文件中的host别名。



原文连接

http://blog.andyhunt.info/2013/11/29/php-mssql-pdo_dblib-freetds-support-on-mac-osx-10-9-mavericks/

http://qa.helplib.com/733737

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:7949次
    • 积分:249
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:1篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论