1

I am receiving an error as below:

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. '

My codes are as follow:

$this->link = new PDO(
                "sqlsrv:server=$this->serverName:$this->port;Database=$this->db",
                "$this->uid",
                "$this->pwd"
                );

I wish someone can enlighten me on what is causing this error. Before that I was using dblib instead of sqlsrv.

"dblib:host=$this->serverName:$this->port;dbname=$this->db"

I am using XAMMP with Apache 2.4.12 and PHP 5.5.24 (they are all x86). I have php_pdo_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll. I am also using Microsoft ODBC Driver 11 for SQL Server-x64.

1 Answer 1

1

Change it to:

$this->link = new PDO(
            "sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
            $this->uid,
            $this->pwd
            );

The default SQL Server port is 1433. Note the curly brackets, they allow for class variables.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.