微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 PHP 中使用另一个文件中的 var

如何解决如何在 PHP 中使用另一个文件中的 var

我试图在 config.PHP 文件中使用 var $db,$db var 是一个准备好的 MysqLi 类 我在我的配置文件中使用这一行

$db = new MysqLiDb ($dbhost,$dbuser,$dbpass,$dbname);

并像这样在我的functions.PHP文件中使用它

    public function save_ship($user = '')
{
    global $db;

然后使用我使用的变量:

array(
            'ship_heder' => $this->$db->escape($arr[$i]['ship_heder']),'ship_num' => $this->$db->escape($arr[$i]['ship_num']),'ship_type' => $this->$db->escape($arr[$i]['ship_type']),'ship_isuf_cust_no' => $this->$db->escape($arr[$i]['ship_isuf_cust_no']),'ship_address' => $this->$db->escape($arr[$i]['ship_address']),'phone_to_call' => $this->$db->escape($arr[$i]['phone_to_call']),'ship_line' => $this->$db->escape($arr[$i]['ship_lines']['0']['ship_line']),'date_time' => $date->format('d/m/Y H:i:s'),'uid' => $user,);

它给了我错误..知道如何解决吗? 谢谢!

解决方法

您只需在代码顶部添加以下行,即可将配置文件包含到 functions.php 中:

include_once('config.php');

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。