我尝试在我的脚本中运行查询并收到此消息。任何人都知道为什么以及如何解决它。
致命错误:调用非对象上的成员函数row()
$query_str = "SELECT MAX(userID) FROM kowmanager_users";
$this->db->query($query_str);
$row = $query->row();
$userID = $row->userID;
编辑:
我在这里找到了这个语法:http://codeigniter.com/user_guide/database/active_record.html#select
为了我的需要想出了这个,但是当我运行脚本时,它给了我一个你的SQL语法错误;检查与MySQL服务器版本对应的手册,以便在第1行的“对象”附近使用正确的语法
文件名:/home/xtremer/public_html/kowmanager/models/user_model.php
$this->db->select_max('userID');
$query_str = $this->db->get('kowmanager_users');
$rows = $this->db->query($query_str);
$userID = $rows->userID;
$userID = $userID + 1;
编辑2:
由于某种原因,更新未运行。
$query_str = "INSERT INTO kowmanager_users (username, password, password2, email, firstName, lastName, accessLevelID) VALUES (?, ?, ?, ?, ?, ?, ?)";
$this->db->query($query_str, array($username, $password[0], $password[1], $email, $firstName, $lastName, '1',));
$id = $this->db->insert_id();
$this->db->select_max('userID');
$query = $this->db->get('kowmanager_users');
$row = $query->row();
$userID = $row->userID;
echo $userID;
echo "<br>";
$userID = $userID + 1;
echo $userID;
$data = array('userID' => $userID);
$where = "id = '".$id."'";
$str = $this->db->update_string('kowmanager_users', $data, $where);
编辑:这是我的完整页面代码: http://pastebin.com/7sJt7V09
答案 0 :(得分:1)
TRY:
$row = $this->db->query->row();
答案 1 :(得分:1)
首先应该更像这样:
$query_str = "SELECT MAX(userID) FROM kowmanager_users";
$q = $this->db->query($query_str);
$row = $q->row();
$userID = $row->userID;
你的第二次尝试应该是这样:
$this->db->select_max('userID');
$q = $this->db->get('kowmanager_users');
$row = $q->row();
$userID = $row->userID;
如果您返回多行,那么您会做这样的事情:
$this->db->select('userID');
$q = $this->db->get('kowmanager_users');
$results = $q->result();
foreach($results as $row)
{
echo $row->userID;
}