2

我有一个公共函数来查询 mysql。在我的本地计算机上一切正常,但是一旦上传到 Godaddy 服务器就会出现问题。基本上,$rows当我调用该方法时,它是空的。

我确信数据库数据是正确的,查询应该返回很少的记录。我花了几个小时试图弄清楚但没有运气。我希望你们能帮助我解决这个问题。提前致谢。

代码

    class test{

     public function getEmployees($username,$password) {



         $stmt = mysqli_prepare($this->connection,
              "SELECT name, password
               FROM employee
               WHERE name='$username' && password='$password'
               ");     

          $this->throwExceptionOnError();

          mysqli_stmt_execute($stmt);
          $this->throwExceptionOnError();

          $rows = array();


          while (mysqli_stmt_fetch($stmt)) {
              $rows[] = $row;
              $row = new stdClass();
              mysqli_stmt_bind_result($stmt,  $row->name, $row->password);
          }
          if(mysqli_stmt_num_rows($stmt)==0){

              return false;
          }else{
              return $rows;
          }



          mysqli_stmt_free_result($stmt);
          mysqli_close($this->connection);
   }

}

$test=new test();
$row=$test->getEmployees('bob','1111');
echo "<pre>";
print_r($row);
echo "</pre>";

//it prints nothing on the page
4

1 回答 1

1

我认为问题在于代码结构。尝试:

class test{

     public function getEmployees($username,$password) {



         $stmt = mysqli_prepare($this->connection,
              "SELECT name, password
               FROM employee
               WHERE name='$username' && password='$password'
               ");     

          $this->throwExceptionOnError();

          mysqli_stmt_execute($stmt);
          $this->throwExceptionOnError();

          $rows = array();
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt,  $row->name, $row->password);

          while (mysqli_stmt_fetch($stmt)) {
              $rows[] = $row;

          }

          mysqli_stmt_free_result($stmt);
          mysqli_close($this->connection);
          $temp = mysqli_stmt_num_rows($stmt); 
          if($temp==0){

              return false;
          }else{
              return $rows;
          }



   }

}

$test=new test();
$row=$test->getEmployees('bob','1111');
echo "<pre>";
print_r($row);
echo "</pre>";
于 2012-05-03T03:22:05.503 回答