PHP致命错误:在user_model.php第46行的字符串上调用成员函数num_rows()。其中第46行是" $ users = $ this-> db-> query($ query) - >结果(); "
它是一个客户订阅包查找器代码 我试图解析客户订阅过期或无效的结果,
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class User_Model extends Base_Model
{
function __construct()
{
parent::__construct();
}
/*** package expire***/
function package_expire()
{
$query = "SELECT u.id,u.is_premium FROM ".$this->db->dbprefix(TBL_USERS)." u, ".$this->db->dbprefix(TBL_USERS_GROUPS)." ug WHERE u.id=ug.user_id AND ug.group_id='2'
AND u.is_premium='1' ";
$users = $this->db->query($query)->result();
if(count($users)>0)
{
foreach($users as $u) :
if($u->is_premium != 0)
{
$user_subscription = $this->base_model->fetch_records_from(TBL_SUBSCRIPTIONS,array('user_id'=>$u->id,'status'=>'Active'));
if(count($user_subscription)>0)
{
$user_subscription = $user_subscription[0];
if(isset($user_subscription->expire_date) && strtotime(date('Y-m-d')) > strtotime($user_subscription->expire_date))
{
$data['status'] = 'In-Active';
$whr['subscription_id'] = $user_subscription->subscription_id;
if($this->base_model->update_operation($data,TBL_SUBSCRIPTIONS,$whr))
{
$user_data['is_premium'] = '0';
$user_data['package_id'] = ' ';
$user_data['no_of_package_quotes'] = 0;
$user_data['no_of_package_quotes_used'] = 0;
$user_whr['id'] = $u->id;
$this->base_model->update_operation($user_data,TBL_USERS,$user_whr);
}
}
}
}
endforeach;
}
}
function getUsers($conditions=array(),$limit=NULL)
{
$str='';
if(count($conditions)>0)
{
if(isset($conditions['admin_read_status']))
$str .= 'AND u.admin_read_status = "'.$conditions['admin_read_status'].'"';
}
$query = 'SELECT u.*,ug.user_id,ug.group_id FROM '.TBL_PREFIX.TBL_USERS.' u
INNER JOIN '.TBL_PREFIX.TBL_USERS_GROUPS.' ug ON u.id=ug.user_id
AND ug.group_id='.GRP_USER.' '.$str.' ';
$resultsetlimit = $this->db->query( $query );
$this->numrows = $this->db->affected_rows();
if($limit != '') $query = $query . ' LIMIT '.$limit;
$resultsetlimit = $this->db->query( $query );
return $resultsetlimit->result();
}
function userSubscriptions($user_id=NULL,$conditions=array())
{
if($user_id=='')
return false;
$str='';
if(count($conditions)>0)
{
if($conditions['status'])
$str .= 'AND s.status = "'.$conditions['status'].'"';
if($conditions['subscription_id'])
$str .= 'AND s.subscription_id = "'.$conditions['subscription_id'].'"';
}
$query = 'SELECT s.*,u.* FROM '.TBL_PREFIX.TBL_SUBSCRIPTIONS.' s
INNER JOIN '.TBL_PREFIX.TBL_USERS.' u ON s.user_id=u.id
AND u.id='.$user_id.' '.$str.' ';
$resultsetlimit = $this->db->query( $query );
$this->numrows = $this->db->affected_rows();
$resultsetlimit = $this->db->query( $query );
return $resultsetlimit->result();
}
}
?>
答案 0 :(得分:0)
看起来您正在尝试从数据库查询中获取受影响的行数。问题是你正在使用的类正在调用一个不存在的变量或函数。
修复是在打开课程后声明它。例如:
class User_Model extends Base_Model
{
public $num_rows = 0;
然后,您可以在运行查询后使用该值。
$user_model = new User_Model();
$query = $user_model->userSubscriptions(whatever goes in here);
echo 'There were ' .$user_model->num_rows.' affected by this query';
答案 1 :(得分:0)
function __construct($db) {
parent::__construct($db);
$this->db = $db;
}
您已经忘记了传递数据库对象,因为您的代码代表User_Model对象正在寻找它无法找到的成员$ this-&gt; db变量(对象)。