Em 2018 eu só deixei aqui o link do guia da Microsoft. Vamos dar contexto: muitas empresas usam SQL Server como banco, e muitos sistemas web são feitos em PHP rodando em Linux. Para os dois conversarem, a Microsoft mantém drivers oficiais.
Os ingredientes
- O driver ODBC da Microsoft para Linux (ver instalação oficial).
- As extensões PHP
sqlsrvepdo_sqlsrv(ver Drivers Microsoft para PHP).
Os comandos exatos mudam com a versão do Ubuntu e do PHP, por isso siga sempre a documentação oficial.
Conectando com PDO
<?php
$dsn = "sqlsrv:Server=localhost,1433;Database=escola;TrustServerCertificate=1";
$pdo = new PDO($dsn, getenv('DB_USER'), getenv('DB_PASS'), [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
$stmt = $pdo->prepare("SELECT TOP 5 nome, nota FROM alunos WHERE turma = ?");
$stmt->execute(['8A']);
foreach ($stmt as $linha) {
echo $linha['nome'] . ' - ' . $linha['nota'] . PHP_EOL;
}
O PDO é uma interface única para vários bancos: trocar de MySQL para SQL Server muda pouco o código. E prepare + execute protegem contra injeção de SQL.
📚 Fontes e para ir além
- Microsoft Drivers for PHP for SQL Server
- PHP: PDO (manual oficial)
- PHP: instruções preparadas no PDO
📝 Publicado originalmente em 6 de novembro de 2018. Revisado, reescrito e com fontes conferidas em outubro de 2026.
Este artigo foi útil ?
SimNão
Last modified: 6 de novembro de 2018
💡 Dica:
TrustServerCertificate=1é só para testes no seu computador. Em produção, configure um certificado válido no SQL Server.💬 Alguém aí usa PHP com algum banco diferente de MySQL? Conta qual e por quê!
Solid platform with a very secure feeling. I feel safe depositing and playing here without worrying about my data. Cheers to vnofen88
The APK is super stable and the loading times are minimal. It feels like a premium casino in my pocket. Check out hannonlinecasinoapk.
I have been exploring different betting platforms lately and finally found a hidden gem that truly understands what players need. The interface is smooth, withdrawals are lightning fast, and the customer support team actually listens to your feedback. If you are looking for a trustworthy place to enjoy your favorite casino games, you really should give this spot a try. It has completely changed how I approach online gaming and I could not be happier with the results. vnf8betnet