How to connect to mssql using pdo through PHP and Linux?

前端 未结 4 672
逝去的感伤
逝去的感伤 2020-11-27 04:58

I\'m trying to for a new PDO connection using the following code.

new PDO(\"mssql:driver=????;Server={$serverName};Database={$databaseName}\", $username, $pa         


        
相关标签:
4条回答
  • 2020-11-27 05:31

    I am running Ubuntu 14.04. Trying to connect to MSSQL I got "Uncaught exception 'PDOException' with message 'could not find driver'". It seems that I was missing the dblib/sybase PHP extension.

    I had to run:

    sudo apt-get install php5-sybase freetds-common libsybdb5 \ 
    && sudo apache2ctl restart
    

    Works fine now.

    0 讨论(0)
  • 2020-11-27 05:38

    The dblib/sybase PHP extension tip posted by Karl Wilbur worked for me. The pre-installation check page for LimeSurvey now shows

    PHP PDO driver library- Microsoft SQL Server (dblib), MySQL

    Just make sure you find and install the version that aligns with the PHP version you are using;

    Prompt>sudo apt-get install php<appropriate version>-sybase freetds-common libsybdb5 Prompt>sudo apache2ctl restart

    Cheers,

    0 讨论(0)
  • 2020-11-27 05:49

    The PDO mssql driver is no more, use sqlsrv (under php windows) or dblib (under php linux)

    http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

    http://www.php.net/manual/en/ref.pdo-dblib.php

    0 讨论(0)
  • 2020-11-27 05:52

    Try

    $dbh = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw");
    
    $hostname may need to be configured as either...
    $hostname.':'.$port;
    

    OR

    $hostname.','.$port;
    
    0 讨论(0)
提交回复
热议问题