Error in sqlsrv_query and sqlsrv_num_rows() functions

Asked

Viewed 128 times

0

Good afternoon, I don’t have much experience in php I’m starting now with this language and I’m having a problem with two functions follows print of the problem:

Warning: sqlsrv_query() expects Parameter 1 to be Resource, bolean Given in ... daoLogin.php on line 17

Warning: sqlsrv_num_rows() expects Parameter 1 to be Resource, Boolean Given in ... daoLogin on line 19

and the code:

<?php

  $server = "Filipe-PC\SQLExpress";
  $database = "bd_CaminhoVerde";
  $user = "caminho_verde";
  $pass = "greenway";

  $infoConexao = array("Database" => $database, "UID" => $user, "PWD" => $pass);
  $conectar = sqlsrv_connect($server, $infoConexao);

  $usuario = $_POST['txtUsuario'];
  $senha = $_POST['txtSenha'];

  $queryLogar = "execute usp_logar @usuario = ?, @senha = ?";
  $parameter = array($usuario, $senha);

  $query_Resultado = sqlsrv_query($conectar, $queryLogar, $parameter);

  if(sqlsrv_num_rows($query_Resultado) > 0)
  {
    session_start();

    $array_Resultado = mssql_fetch_array($query_Resultado);
    $_SESSION['cpf'] = $array_Resultado['cpf'];
    $_SESSION['nome'] = $array_Resultado['nome'];
    $_SESSION['creditos'] = $array_Resultado['creditos'];
    $_SESSION['usuario'] = $array_Resultado['usuario'];

    header("Location:home.php");
  }
  else{ }

 ?>

Thank you for your attention

Note: it already extracts the drivers from php_sqlsrv_56_ts and php_pdo_sqlsrv_56_ts and referenciei in php.ini

Error array with sql-server:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Nome da fonte de dados n�o encontrado e nenhum driver padr�o especificado [message] => [Microsoft][ODBC Driver Manager] Nome da fonte de dados n�o encontrado e nenhum driver padr�o especificado ) )
  • vc run this sp directly on the bank? the error only says that failed the query.

  • on the bench the sp ta running good, no error

  • With this user and password you can run other queries by php? for what $conectar received false, so the connection was not made.

  • I made another code to test the connection as you said and found the error array with sql, I’ll put it at the end of the question

  • Install the ODBC there that should solve.

  • Yes I installed yesterday and fixed, like I uninstalled several times the php pq drivers the microsoft solution links always led me to new drivers and was problem with ODBC

  • vlw ai for help

Show 2 more comments
No answers

Browser other questions tagged

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