php如何读取和修改例如config.php配置文件中的字符串
phpcn_u315
phpcn_u315 2017-01-22 21:10:22
0
3
1636

因为考虑到数据库连接的问题,於是像吧MySQL连接的信息放到Config.php文件中:

Config.php

如下:

<?php 
//站点配置文件
/*****数据库连接配置*****/
$db_host="localhost";
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "test";
?>

那么该怎么读取Config.php中的信息呢?比如读取$db_host的值是localhost。

怎么修改后面的值呢???



phpcn_u315
phpcn_u315

reply all(3)
数据分析师

How does php read and modify strings in configuration files such as config.php-PHP Chinese Network Questions and Answers-How does php read and modify strings in configuration files such as config.php-PHP Chinese Network Questions and Answers

Take a look around and learn.

左手右手慢动作

如果是原生的require引入 直接输出变量echo $db_host 就能得这个值   框架一般都可以通过常量获取 比如thinkphp是通过大C直接获取的

阿神

用include或者require引入一下这个文件就可以了,引入之后可以读取或者修改

  • reply 引入倒是好弄。那么怎么通过一个php页面来修改这个$db_host的值。谢谢。
    phpcn_u315 author 2017-01-23 12:23:40
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!