请问我有codeigniter的问题。当我尝试登录这里是结果:
以下相关文件的代码:
NSArray *currentFighters = [[segment valueForKeyPath:@"fighters"] allObjects];
NSLog(@"----- current fighters ---- ");
for (FCFighter *fighter in currentFighters) {
NSLog(@"%@", [fighter description]);
}
NSMutableArray *currentFightersMutable = [currentFighters mutableCopy];
[currentFightersMutable replaceObjectAtIndex:fighterIdx withObject:pickedFighter];
NSArray *updatedFighters = [currentFightersMutable copy];
NSLog(@"----- updated fighters ---- ");
for (FCFighter *fighter in updatedFighters) {
NSLog(@"%@", [fighter description]);
}
[segment setFighters:[NSSet setWithArray:updatedFighters]];
NSLog(@"----- [segment fighters] ---- ");
for (FCFighter *fighter in [[segment valueForKeyPath:@"fighters"] allObjects]) {
NSLog(@"%@", [fighter description]);
}
我一直在寻找解决方案并找到了这篇文章(Call to a member function num_rows() on boolean)。它给了我一个想法,但没有真正的帮助。感谢
答案 0 :(得分:1)
这样的计数:
$this->db->select('id');
$this->db->from('table');
$this->db->where($your_conditions);
$num_results = $this->db->count_all_results();
答案 1 :(得分:1)
在启用MySQL严格模式的情况下出现此错误。当我禁用严格模式时,错误消失了。
要检查此模式是否已启用
SHOW VARIABLES LIKE 'sql_mode';
使其禁用
SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
答案 2 :(得分:0)
**尝试这样的事情**
//this function checks whether the username and the password is in the database or not
public function check_login($username, $password){
$this->db->select('username, password, status');
$array = array('username' => $username, 'password' => sha1($password),'status' => 'active');
$this->db->where($array);
$query = $this->db->get('user');
$result = $query->result();
if($result->num_rows() == 1) // if the affected number of rows is one
{
return true;
}
else
{
return false;
}
}
答案 3 :(得分:0)
如果没有结果,CODEIGNITER会将boolean作为结果发送 例如按照你的方法
public function check_login($username, $password){
$this->db->select('username, password, status');
$array = array('username' => $username, 'password' => sha1($password),'status' => 'active');
$this->db->where($array);
$query = $this->db->get('user');
if($query->num_rows() == 1) // if the affected number of rows is one
{
return true;
}
else
{
return false;
}
如果表中没有数据,那么在我们期待一些我们可以工作的对象之前发送False,所以在调用 $ query-> num_rows()之前检查它是否是一个对象所以代码可以像:
$query = $this->db->get('user');
if(is_object($query)){
if($query->num_rows() == 1) // if the affected number of rows is one
{
return true;
}
}else{
return false;
}
答案 4 :(得分:0)
您可以这样写。它将顺利运行。
if($query !== FALSE && $query->num_rows() == 1) // if the affected number of rows is one
{
return true;
}
else
{
return false;
}