0
I have the following PHP:
<?php
class Conexao
{
private static $connection;
private function __construct(){}
public static function getConnection() {
$pdoConfig = DB_DRIVER . ":". "Server=" . DB_HOST . ";";
$pdoConfig .= "Database=".DB_NAME.";";
try {
if(!isset($connection)){
$connection = new PDO($pdoConfig, DB_USER, DB_PASSWORD);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
return $connection;
} catch (PDOException $e) {
$mensagem = "Drivers disponiveis: " . implode(",", PDO::getAvailableDrivers());
$mensagem .= "\nErro: " . $e->getMessage();
throw new Exception($mensagem);
}
}
}
define('DB_HOST' , "dblinx");
define('DB_USER' , "maicon.friedel");
define('DB_PASSWORD' , "Mf2681");
define('DB_NAME' , "Linx");
define('DB_DRIVER' , "sqlsrv");
try{
$Conexao = Conexao::getConnection();
$query = $Conexao->query("SELECT nome, preco, quantidade FROM produto");
$produtos = $query->fetchAll();
}catch(Exception $e){
echo $e->getMessage();
exit;
}
?>
<table border=1>
<tr>
<td>Nome</td>
<td>Preço</td>
<td>Quantidade</td>
</tr>
<?php
foreach($produtos as $produto) {
?>
<tr>
<td><?php echo $produto['nome']; ?></td>
<td>R$ <?php echo $produto['preco']; ?></td>
<td><?php echo $produto['quantidade']; ?></td>
</tr>
<?php
}
?>
</table>
But this always comes up:
And as you can see, I’ve put the right drivers, version 7.2 PHP, drivers for the right version:
You are using a tool like WAMP, you can share something else from your setup. for example your php.ini
– Jorge Costa
I added Extensions in php.ini..
– maiconfriedel
You have installed the ODBC https://docs.microsoft.com/pt-br/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-2017drivers
– Jorge Costa
Yes, I installed the ODBC drivers and keeps showing the same message
– maiconfriedel
Your PHP is x86 or x64
– Jorge Costa
x64.................
– maiconfriedel