dongxie3701 2016-12-06 16:08
浏览 93

将PHP MSSQL PDO与Plesk一起使用

My current Website Control Panel is PLESK Parallels, and i'm trying to use PDO MSSQL on my website.

I've searched the internet and i'm aware that the PDO dll needs to be in my php.ini file and such, but I keep reading different ways to do it all the time, using commands like YUM and i'm getting confused.

Can someone possibly, in plain, simple black and white instructions, explain the process so I can simply run code like this

try {
$hostname = "myhostname";
$port = myportnumber;
$dbname = "databasename";
$username = "user";
$pw = "password";
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "
";
exit;
}

When I load my page where this command is located i get the error message

'Failed to get DB handle: could not find driver'

Thanks

  • 写回答

2条回答 默认 最新

  • duanou8504 2016-12-07 07:05
    关注

    Example of installing pdo_dblib on CentOS-like OS for Plesk PHP 5.6:

    # yum install plesk-php56-devel
    # /opt/plesk/php/5.6/bin/pecl download pdo_dblib
    # tar -xzf PDO_DBLIB-1.0.tgz
    # cd PDO_DBLIB-1.0/
    # /opt/plesk/php/5.6/bin/phpize
    # ./configure --with-php-config=/opt/plesk/php/5.6/bin/php-config --with-pdo-dblib=./freetds
    
    # vim pdo_dblib.c
    

    On line #37 replace:

    function_entry pdo_dblib_functions[] = {
    

    with:

    zend_function_entry pdo_dblib_functions[] = {
    

    Save file and:

    # make
    # make install
    

    you should see something like

    Installing shared extensions:     /opt/plesk/php/5.6/lib64/php/modules/
    

    Enable extension:

    # echo "extension=pdo_dblib.so" >> /opt/plesk/php/5.6/etc/php.d/pdo_dblib.ini
    

    Verify:

    # /opt/plesk/php/5.6/bin/php -m | grep pdo_dblib
    pdo_dblib
    

    Now sites in Plesk with PHP handler 5.6 will work with:

    $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
    

    Pay attention for :

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测