Problems with external SQL Server connection in PHP

Asked

Viewed 326 times

0

I am with a problem for days with an external connection PDO sqlsrv, I have scanned the internet and I did not find a solution.

I installed all sql server drivers for PHP, including, I installed sql server on my machine to test a local connection and it worked... however, the external connection does not work in PHP. I can connect normally on the external server by SQL Management Studio, putting IP, user and password.

Here is the code and the error:

try
{

    $servidor = "aqui vai o ip";
    $instancia = "instancia";
    $porta = 1433;
    $database = "banco";
    $usuario = "usuairo";
    $senha = "senha";

    $conexao = new PDO( "sqlsrv:Server={$servidor}\\{$instancia},{$porta};Database={$database}", $usuario, $senha );
}
catch ( PDOException $e )
{
    echo "Drivers disponiveis: " . implode( ",", PDO::getAvailableDrivers() );
    echo "<br> Erro: " . $e->getMessage();
}

Error:

Drivers disponiveis: mysql,odbc,sqlite,sqlsrv
 Erro: SQLSTATE[28000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Falha de logon do usuário 'usuairo'.

Someone helps??

  • You created the Language for the database on your server?

  • @Pbras, yes, user and password, works in Management Studio, but not in PHP

1 answer

0


Tries: new PDO("sqlsrv:server={$server};Database={$database}" $user, $pass);

  • Obg, had already solved, your answer is equal to the example in my question, with the difference of instance. Error occurred because an employee who took care of the server had blocked this user.

  • is that in your question you have a " " and I traded for ";"

Browser other questions tagged

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