In many projects, configuration files are indispensable. Typically, configuration files are set with variables or arrays, such as databases, or some public parameters.

create

<? $config = array('DB_URL' => 'localhost', 'DB_USER' => 'root', 'DB_PWD' => 'root', 'DB_NAME' => 'test_db' ); $STR = '<? PHP '. PHP_EOL. '/ * *'. PHP_EOL. '* configuration file'. PHP_EOL. '* TANKING'. PHP_EOL. '*'. The date (' Y -m - d '). ' '. PHP_EOL. '* /'. PHP_EOL. '$db_config =  '.var_export($config,true).'; '.PHP_EOL.'? > '; $file = fopen("config.php","w"); $file = fopen("config.php","w"); echo fwrite($file,$str); fclose($file); ? >

The configuration file

<? $db_config = array ('DB_URL' => 'localhost', 'DB_USER' => 'root', 'user' => 'root'); 'DB_PWD' => 'root', 'DB_NAME' => 'test_db', ); ? >

How to read?

<? PHP // include './config.php'; / / create a connection $conn = mysqli_connect ($db_config [' DB_URL], $db_config [' DB_USER], $db_config [' DB_PWD ']); // Check the connection if (! $conn) { die("Connection failed: " . mysqli_connect_error()); } echo "Connected successfully "; ? >

The author

Author:TANKING

DateL2021-04-25

WeChat:sansure2016

Web:http://www.likeyuns.com