简体   繁体   中英

How to use var from another file with PHP

I am trying to use var $db in config.php file, the $db var is a mysqli class ready I use this line in my config file

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

and use it inside of my functions.php file like this

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

and then to use the var i use:

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,
        );

and it gives me error.. any idea how to solve? thanks!

You need to include your config file to functions.php by just adding this line at the top of your code:

include_once('config.php');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM