如何使用数组连接数据库 class
How connect database class with an array connect
我如何连接到另一个脚本我的数据库 class 功能?
我需要在不使用连接文件更改每个文件的情况下完成它。
这是我的配置文件(conn.php):
define('DB_HOST', "localhost");
define('DB_TYPE', "mysql");
define('DB_USER', "user");
define('DB_PASS', "123456");
define('DB_NAME', "dbuser");
这是我需要更改为 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'] = '';
您已经定义了常量,因此无需用引号或连接将其括起来。
使用引号将被视为字符串文字。
$config = array();
$config['database']['host'] = DB_HOST;
$config['database']['user'] = DB_USER;
$config['database']['password'] = DB_PASS;
$config['database']['database'] = DB_NAME;
参考文献:
我如何连接到另一个脚本我的数据库 class 功能? 我需要在不使用连接文件更改每个文件的情况下完成它。
这是我的配置文件(conn.php):
define('DB_HOST', "localhost");
define('DB_TYPE', "mysql");
define('DB_USER', "user");
define('DB_PASS', "123456");
define('DB_NAME', "dbuser");
这是我需要更改为 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'] = '';
您已经定义了常量,因此无需用引号或连接将其括起来。
使用引号将被视为字符串文字。
$config = array();
$config['database']['host'] = DB_HOST;
$config['database']['user'] = DB_USER;
$config['database']['password'] = DB_PASS;
$config['database']['database'] = DB_NAME;
参考文献: