Home  >  Article  >  Backend Development  >  What is the name of the php database configuration file?

What is the name of the php database configuration file?

(*-*)浩
(*-*)浩Original
2019-09-26 14:25:153772browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn