Select query returning false on sql server in PHP

A

Anonymous

Guest
I am using SQL(MSSQL) Server database on Windows Server. My database connection is working perfect. I am trying to get data using Select Query. Here is my code,

db_functions.php

Code:
 public function login($username, $password)
 {

   $sqlString = "SELECT CompId , BUCode , Role from 
   PRIME_APPUSR WHERE UserName = ? AND PassWord = ?";

   $params = array($username, $password);

    $stmt = sqlsrv_query($this->conn, $sqlString, $params);
    if ($stmt === false) {

        die(print_r(sqlsrv_errors(), true));
    }

    $rows = sqlsrv_has_rows($stmt);

    if ($rows === true) {

        while ($row = sqlsrv_fetch($stmt)) {

            $response["CompId"] = sqlsrv_get_field($stmt, 0);
            $response["BUCode"] = sqlsrv_get_field($stmt, 1);
            $response["Role"]   = sqlsrv_get_field($stmt, 2)

        }

        return $response;

    } else {
        return false;
    }

}

login.php

Code:
 <?php

  require_once 'db_functions.php';
  $db = new db_functions();

  if (isset($_POST['USERNAME']) && isset($_POST['PASSWORD'])) {

  $USERNAME = $_POST['USERNAME'];
  $PASSWORD = $_POST['PASSWORD'];

  $result1 = $db->login($USERNAME, $PASSWORD);

  if (!$result1) {

    $arr["response"] = "Error.";

  } else {

    $arr["response"] = $result1;

  }

  echo json_encode($arr);

  } else {

    $arr["response"] = "Invalid Parameters";
    echo json_encode($arr);

  }

?>

my question is , i am getting a false in return from this function. can anyone guide to solve this.?
 
Back
Top