私は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