use*_*149 2 php database database-connection
如何将我的数据库类函数连接到另一个脚本?我需要在不更改连接文件的每个文件的情况下完成它.
这是我的配置文件(conn.php):
define('DB_HOST', "localhost"); 
define('DB_TYPE', "mysql"); 
define('DB_USER', "user"); 
define('DB_PASS', "123456"); 
define('DB_NAME', "dbuser"); 
Run Code Online (Sandbox Code Playgroud)
这是我需要更改为DEFINE连接的配置:
include_once('../conn.php'); # is the file with the connection
$config = array();
$config['database']['host'] = 'localhost';    # I tried with .DB_HOST.
$config['database']['user'] = '';        # I tried with .DB_TYPE.
$config['database']['password']  = '';      
$config['database']['database'] = '';      
Run Code Online (Sandbox Code Playgroud)
    您已经定义了常量,因此无需将其包装在引号或连接中.
使用引号将被视为字符串文字.
$config = array();
$config['database']['host'] = DB_HOST;
$config['database']['user'] = DB_USER;
$config['database']['password']  = DB_PASS;      
$config['database']['database'] = DB_NAME;
Run Code Online (Sandbox Code Playgroud)
参考文献: