如何在 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');