Home > Article > Backend Development > What is the name of the php database configuration file?
Create database configuration file in php code. (Recommended learning: PHP programming from entry to proficiency)
Write the database user name, password and other information to the configuration file config.php, and reference the configuration file when needed Use include or require in the content file, and use the global keyword in the function to globalize the variables that store the database name, password, etc., so that they can be used in the function in the file.
1, config.php database configuration file:
<?php $db_name="test"; $db_username="root"; global $db_password; ?>
Database operation class (calling configuration file) db.fun.php:
<?php require("config/config.php"); class db{ function fun(){ global $db_username,$db_password; echo "数据库用户名:".$db_username."<br />"; echo "数据库密码:".$db_password."<br />"; } } ?>
Application file test.php:
<?php require("include/db.fun.php"); $a= new db(); $a->fun(); ?>
The above is the detailed content of What is the name of the php database configuration file?. For more information, please follow other related articles on the PHP Chinese website!