例如,我有两个文件:
//db.php
return array(
'server'=>'localhost',
'db'=>'mydb',
'name'=>'root',
'password'=>'root',
);
和第二个文件:
//index.php
$config = (include 'db.php');
之后,如果包含文件,则为$config = 1
,如果不包含文件,那么为$config = 0
,但$config
必须是db.php
文件中的array()
。
什么问题?
windows 7x64、apache 2.2、php 5.4
您可以使用INI文件作为DB凭据。不要忘记拒绝访问.htaccess文件中的config.ini。
config.ini
[database]
server = localhost
db = mydb
name = root
password = root
index.php
<?php
$config = parse_ini_file('config.ini');
// Access to credentials
echo $config['server'];
?>
<? The array is not supposed to be output at all; if it is, something's wrong with your file. In this case, PHP isn't configured to handle short open tags