model
<code> 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();
}
}
}
</code>报错
<code><h4>A PHP Error was encountered</h4> <p>Severity: Notice</p> <p>Message: Undefined variable: hsh</p> <p>Filename: models/stock_model.php</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p>Line Number: 22</p> </div><br /> <b>Fatal error</b>: Call to a member function where() on a non-object in <b>D:\htdocs\application\models\stock_model.php</b> on line <b>22</b><br /> </code>
刚学,很多问题不懂 ! 这是用的CI
model
<code> 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();
}
}
}
</code>报错
<code><h4>A PHP Error was encountered</h4> <p>Severity: Notice</p> <p>Message: Undefined variable: hsh</p> <p>Filename: models/stock_model.php</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p>Line Number: 22</p> </div><br /> <b>Fatal error</b>: Call to a member function where() on a non-object in <b>D:\htdocs\application\models\stock_model.php</b> on line <b>22</b><br /> </code>
刚学,很多问题不懂 ! 这是用的CI
<code class="lang-php">//$this->hsh = $_ci->load->database('hsh',TRUE);
$hsh = $_ci->load->database('hsh',TRUE);
</code>Message: Undefined variable: hsh
未定义变量hsh
你把$hsh都改为$this->hsh。
随便建议一下,应该把基础打好了再用框架,过早使用框架只会抑制你的成长。
$hsh 换成 $this->hsh
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号