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

What is the name of the php database configuration file?

(*-*)浩
Release: 2023-02-25 06:54:01
Original
3894 people have browsed it

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;
?>
Copy after login

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 />";
}
}
?>
Copy after login

Application file test.php:

<?php
require("include/db.fun.php");
$a= new db();
$a->fun();
?>
Copy after login

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!

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template