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?
– durtto
Thanks.Yes I checked, because it shows nothing either
– KevinF
You need to check for errors. Enable your php to show errors
– durtto
Look at that answer, can help you a lot.
– durtto
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.
– KevinF
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.– rray
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.
– KevinF
So it’s all right, just missed making a query, as there is no exit the page goes blank even.
– rray
Okay, worked out with consultation haha thanks.
– KevinF
In dsn, change the ip, by the name of the instant host, something like
Server=servidorDeBanco\NomeDoSQLServer
;– rray
Is that the server is not hosted on the machine.
– KevinF
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.
– durtto
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;");
 while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) {
 echo "Login: {$linha['Dslogin']} - Senha: {$linha['DsSenha']}<br />";
}
– KevinF
The answer of the rray cleared everything.
– KevinF