2

私はmysqlのクエリを実行するパブリック関数を持っています。ローカル コンピューターではすべて問題なく動作しますが、godaddy サーバーにアップロードすると問題が発生します。基本的に、$rowsメソッドを呼び出したときは null です。

データベースのデータは正しいと確信しており、クエリはほとんどレコードを返さないはずです。私はそれを理解しようと何時間も費やしましたが、運がありません。皆さんがこれについて私を助けてくれることを望んでいました。前もって感謝します。

コード

    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 に答える