How to connect PHP to Sqlserver via PDO

Asked

Viewed 9,506 times

5

I’m using the following code:

try {

    $con = new PDO("sqlsrv:Server=172.20.21.193,9090;Database=sgt","deb","123123");

    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  

} catch (PDOException $e) {
    die ("Erro na conexao com o banco de dados: ".$e->getMessage());
}

but is giving error when trying to connect. PDO driver is installed. Which other library or driver should I install so my application can access the database? PHP version is 5.6.9 (Linux Debian 8.1) and Sqlserver is 2008 (access will be remote).

  • 1

    Which error appears?

  • 1

    This "could not find driver"

  • 1

    You need to install it first, see the procedure on this link http://answall.com/q/48078/91

  • 1

    Even for Linux? These would be the steps?

  • 1

    On Linux, I can’t say, edit the question and add this information in more detail helps other users to answer better.

  • Try PDO_DBLIB: http://php.net/manual/en/ref.pdo-dblib.php or PDO_ODBC with linux driver, as described here: http://php.net/manual/en/ref.pdo-sqlsrv.php

Show 1 more comment

2 answers

4

  • I’m having the same problem, but the above solution didn’t help me @Deb

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.