class stock_model extends ci_model{ private $hsh; function __construct() { parent::__construct(); $_ci = & get_instance(); //$this->hsh = $_ci->load->database('hsh',true); $hsh = $_ci->load->database('hsh',true); } function get_stock($goods_huo) { if(isset($goods_huo)) { $hsh->where('item_huo',$goods_huo); $query = $hsh->get('item_info'); return $query->result_array(); $query->free_result(); } } }
报错
a php error was encounteredseverity: notice
message: undefined variable: hsh
filename: models/stock_model.php
line number: 22
fatal error: call to a member function where() on a non-object in d:\htdocs\application\models\stock_model.php on line 22
刚学,很多问题不懂 ! 这是用的ci
回复内容: model
class stock_model extends ci_model{ private $hsh; function __construct() { parent::__construct(); $_ci = & get_instance(); //$this->hsh = $_ci->load->database('hsh',true); $hsh = $_ci->load->database('hsh',true); } function get_stock($goods_huo) { if(isset($goods_huo)) { $hsh->where('item_huo',$goods_huo); $query = $hsh->get('item_info'); return $query->result_array(); $query->free_result(); } } }
报错
a php error was encounteredseverity: notice
message: undefined variable: hsh
filename: models/stock_model.php
line number: 22
fatal error: call to a member function where() on a non-object in d:\htdocs\application\models\stock_model.php on line 22
刚学,很多问题不懂 ! 这是用的ci
//$this->hsh = $_ci->load->database('hsh',true);$hsh = $_ci->load->database('hsh',true);
message: undefined variable: hsh
未定义变量hsh
你把$hsh都改为$this->hsh。
随便建议一下,应该把基础打好了再用框架,过早使用框架只会抑制你的成长。
$hsh 换成 $this->hsh
