Connection database sql server 2008 PDO

Asked

Viewed 167 times

1

I’m using the following code:

try {

$con = new PDO("sqlsrv:Server=ip;Database=nome","nome","12345");

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


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

I’m trying to connect to a database sql server 2008, and I’m using xampp because the screen turns white. I already checked the Extension in php.ini and everything else.

  • Welcome to the site. You can view the browser console to try to verify the error?

  • Thanks.Yes I checked, because it shows nothing either

  • You need to check for errors. Enable your php to show errors

  • Look at that answer, can help you a lot.

  • I have done all this procedure, and my php is already with (display_errors = On), the page is simply blank I do not know if it is code or php error.

  • Which php version are you using? Blank screen is programming error, add these two lines at the top of the page, ini_set('display_errors', true); error_reporting(E_ALL); Don’t forget to see, phpinfo() if the extension has been installed/loaded correctly.

  • Apparently it’s all right the php version I use is 5.6.14 and contains the Extension php_pdo_sqlsrv_56_ts.dll and php_sqlsrv_56_ts.dll, sqlsrv Pdo driver is also listed as installed. Even with this line of code the page remains blank.

  • So it’s all right, just missed making a query, as there is no exit the page goes blank even.

  • 1

    Okay, worked out with consultation haha thanks.

  • In dsn, change the ip, by the name of the instant host, something like Server=servidorDeBanco\NomeDoSQLServer;

  • Is that the server is not hosted on the machine.

  • Great, good you made it! Now we need to create a correct answer to your question, so that other users can be helped as well as you. Which comment was critical to solving your situation? If everyone helped, then create an answer to your question.

  • 1

    The code above is correct, but will not show anything on the screen if you do not consult. Below I used this code to test the connection and see if it returned something: $consulta = $con->query("SELECT Dslogin, DsSenha FROM SISWEBUSU;");&#xA; while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {&#xA; echo "Login: {$linha['Dslogin']} - Senha: {$linha['DsSenha']}<br />";&#xA;}

  • The answer of the rray cleared everything.

Show 9 more comments
No answers

Browser other questions tagged

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