I am having a public function doing query for mysql. Everything works great in my local computer but having trouble once it was uploaded to the godaddy server. Basically, the $rows is null when I called the method.
I am sure the database data are correct and the query should return few records. I have spent hours trying to figure it out but have no luck. I was hoping you guys can help me out on this one. Thanks in advance.
Code
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