ERROR NO PHP: Fatal error: Call to undefined function sqlsrv_query ()

0

My login validation is giving this error: Fatal error: Call to undefined function sqlsrv_query() every time I try to login to the site I created. I made the connection to the db SQL SERVER:

    <?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'        , "---");
define('DB_USER'        , "--");
define('DB_PASSWORD'    , "--");
define('DB_NAME'        , "--");
define('DB_DRIVER'      , "--");

?>

And the login:

<?php

require_once "config/conexao.php";

if(isset($_REQUEST['valida'])){
    $var1 = $_REQUEST['codMont'];

        $sql = "SELECT AQUI";

        $stmt = sqlsrv_query($conn, $sql);

        if(sqlsrv_num_rows ($stmt) > 0 )
        {
        $_SESSION['codMont'] = $var1;        
        header('location:home.php');
        }
        else{
        unset ($_SESSION['codMont']);       
        header('location:index.php');
        }
}
?>

But every time I try to login, it gives me this error: Fatal error: Call to undefined function sqlsrv_query() and I already put the drives:

php_sqlsrv_7_ts_x86.dll php_pdo_sqlsrv_7_ts_x86.dll

php_sqlsrv_54_nts.dll php_sqlsrv_53_nts.dll php_sqlsrv_54_ts.dll php_sqlsrv_53_ts.dll

My php version: 5.6.14

Does anyone have a solution to my problem?

    
asked by anonymous 07.06.2018 / 13:37

1 answer

0

According to the documentation PHP to sqlsrv_query() , make sure the version of your PHP and the SQLSRV version you are using are equivalent:

$serverName = "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
     die( print_r( sqlsrv_errors(), true));
}

$sql = "INSERT INTO Table_1 (id, data) VALUES (?, ?)";
$params = array(1, "some data");

$stmt = sqlsrv_query( $conn, $sql, $params);
if( $stmt === false ) {
     die( print_r( sqlsrv_errors(), true));
}
  

Here to reference

If you instantiated a PDO connection, the executions should be PDO , try to migrate everything to sqlsrv .

The PDO class has access to several different databases, if you want to use PDO :

  

Here the SQLSRV PDO reference

    
07.06.2018 / 14:00