SQL Connection with PHP does not find the Drivers

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>

However, this always appears:

Andasyoucansee,Iputtherightdrivers,version7.2PHP,driversofthecorrectversion:

    
asked by anonymous 19.07.2018 / 20:45

2 answers

2

Well let's get started, you need to:

Install a driver on your pc, and your php, but you already installed it in php, correct?

See this ODBC and install: link

If you have more questions, you can look at the link

    
20.07.2018 / 17:50
0

The Microsoft Web site explains what is required for the connection to SQL Server.

It's probably missing you include the extensions in your php.ini

The file is in the same path as your dlls.

The step-by-step is for SQL Server 2017, however it is only to adapt the version you are using.

Here's a step-by-step reference:

link

    
19.07.2018 / 21:49