How can I connect to php with sqlserver (pdo)? It sounds simple, but I can not ... Already enabled the driver everything ok Attached is the name of the server, I'll run it on the site ...
You have two options to try:
$pdo = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw");
or
$pdo = new PDO( "sqlsrv:server=$serverName ; Database=$dbname", "$username", "$pw");
It depends on the driver you installed in PHP.
[Edited] An example of a select with PDO
//retornar o resultset
$sql = 'Select * from products';
$result = $pdo->query($sql);
// imprimir resultados um a um
while ($campos = $result->fetch()){
echo $campos['ProductID']. ' - '.$campos['ProductName'].'<br />';
}
Good evening. If you do not have the extensions sqlsrv and pdo_sqlsrv, it is best to try with odbc. Here's how:
$pdo = new \PDO ("odbc:Driver={SQL Server Native Client 11.0};Server=localhost;Database=catalogName;app=appName;WISD={$_SERVER['REMOTE_HOST']}",$sqlUser,$sqlPass);
What version of PHP are you using? Can you send a print of phpinfo in the PDO area similar to the image below? See if in PHP configuration is enabled pdo_sqlsrv, because it seems to me that this driver you already have.