如何将此行代码转换为MSSQL Server 2012将接受的查询?
我收到此错误在C:\ xampp \ htdocs \ pis \ application \ models \ main.php中调用boolean上的成员函数num_rows()当我试图将其转换为查询mssql
function login($username, $password) {
$this -> db -> select();
$this -> db -> from('tbl_user');
$this -> db -> JOIN('tbl_assign_role', 'tbl_user.u_id = tbl_assign_role.tar_owner_id');
$this -> db -> where('tbl_user.u_uname = ' . "'" . htmlspecialchars($username) . "'");
$this -> db -> where('tbl_user.u_pword = ' . "'" . MD5($password) . "'");
$this -> db -> where('tbl_user.is_active = 1');
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
我把它改成了这个
$query = "SELECT * FROM tbl_user
LEFT JOIN tbl_assign_role ON tbl_user.u_id = tbl_assign_role.tar_owner_id
WHERE tbl_user.u_name = '".$username."'
AND tbl_user.u_pword = '".MD5($password)."'
AND tbl_user.is_active = 1
FETCH NEXT 1 ROWS ONLY
";
我改变后,这就成了错误。
现在正在运作。我所做的是
$query = "SELECT TOP 1 * FROM tbl_user
JOIN tbl_assign_role ON tbl_user.u_id = tbl_assign_role.tar_owner_id
WHERE tbl_user.u_uname = '".htmlspecialchars($username)."'
AND tbl_user.u_pword = '".MD5($password)."'
AND tbl_user.is_active = 1";
$query = $this->db->query($query);
答案 0 :(得分:0)
希望这对你有帮助......
"SELECT tbl_user.*,tbl_assign_role.* FROM tbl_user left join tbl_assign_role on tbl_assign_role.tar_owner_id = tbl_user.u_id where tbl_user.u_uname = '".htmlspecialchars($username)."' and tbl_user.u_pword ='".MD5($password)."' and tbl_user.is_active='1' limit 1";