SQL connection with PHP does not find the Drivers

Asked

Viewed 379 times

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:

inserir a descrição da imagem aqui

And as you can see, I’ve put the right drivers, version 7.2 PHP, drivers for the right version:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

  • You are using a tool like WAMP, you can share something else from your setup. for example your php.ini

  • I added Extensions in php.ini..

  • 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

  • Yes, I installed the ODBC drivers and keeps showing the same message

  • Your PHP is x86 or x64

  • x64.................

Show 1 more comment

2 answers

2


  • Man... thanks so much! Looking at these two tutorials you went through, it worked! Thanks so much.

0

Browser other questions tagged

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