SQLSRV无法获取PHP中的SqlSrv_Num_Rows返回空白结果

时间:2014-05-13 16:34:52

标签: php sql-server sqlsrv

我正在尝试使用php打印sqlsrv_num_rows。出于某种原因,他们没有被退回。我创建了一个简单的登录系统,检查数据库的用户名和密码,然后返回现在的数字。我没有错误只是一个空白屏幕。

我的连接正常,我可以打印其他变量,只是无法检索数字。我的代码如下:

ini_set("display_errors",1); 
error_reporting(E_ALL);

$user   = $_POST['username'];
$pass   = md5($_POST["password"]);

//connect to db
require "db.php";

if(!(isset($user) && isset($pass))) {
   echo "A registered userid and password is required. 
           Please check your userid and/or password";
}

session_start();

if(isset($user) && isset($pass)) {
   //get userid and level from users table according to username and password entered
   $sql = "SELECT * FROM dbo.users WHERE userid = '$user' and psw = '$pass'";

   $params = array($user, $pass);

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

   //$username = $row['userid'];
   //$level = $row['lvl'];

   //if query does not work, return false
   if($stmt === false) {
      die( print_r( sqlsrv_errors(), true));
   }

   //print "$user";

   $numrows = sqlsrv_num_rows($stmt);

   if (count($numrows) == 1) {
      while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
         print_r($row);
      }
   }
}

0 个答案:

没有答案