我是OOP的新手,我有一个mysqli类包装器用于我的数据库。有方法不在包装器,我想在我的查询中使用它们,我只是不知道如何在类中添加它们。
我的班级在这里https://bitbucket.org/getvivekv/php-mysqli-class/src/f72d10285e9327681109871dccd99e23891bfde9/class.database.php?at=master
我需要统计一个select语句的行数。
这就是我所做的
$where = array(
'staff_id' => 'Input::get("staff_id")',
'role' => 'Input::get("role")'
);
$sel = $db->select()->from('staff_role')->where($where) ;
$total = mysqli_num_rows($sel);
if($total==0){
}
我得到这个警告
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result.
请帮忙
两件事:
1)验证这些行,当你调用这些方法时,你真的需要引号吗?
'staff_id' => 'Input::get("staff_id")',
'role' => 'Input::get("role")'
2)你的包装类有一个你没有调用的方法execute(),它应该像这样
$sel = $db->select()->from('staff_role')->where($where)->execute();
现在您应该得到结果集。如果sql语句中有任何问题,包装器将抛出错误。要获得count,可以输入
$db->affected_rows
使用query()代替execute()方法获取结果