Home > Backend Development > PHP Tutorial > How to use database configuration file in php

How to use database configuration file in php

WBOY
Release: 2016-07-25 09:04:49
Original
2895 people have browsed it
Introduction: Save the database user name, password, etc. in the configuration file config.php, and then use include or require where needed to include them, and use the global keyword in the function to globalize the variables storing the database name, password, etc. It can be used in functions in the file.

Introduction: Save the database username, password, etc. in the configuration file config.php, then use include or require where needed, and use the global keyword in the function to make the variables storing the database name, password, etc. global ized, it can be used in functions in the file. 1. Configuration file -config.php:

How to use database configuration file in php

2. Database operation class (call configuration file) db.fun.php:

How to use database configuration file in php

3. Application file test.php:

How to use database configuration file in php

There will be no output from this script because the echo statement refers to a local version of the variable $a, and it is not assigned a value in this scope. PHP's global variables are slightly different from C language. In C language, global variables automatically take effect in functions unless overridden by local variables. This can cause problems and may inadvertently change a global variable. Global variables in PHP must be declared global when used in functions. 4. Global file calling example

How to use database configuration file in php

The output of the above script will be "3". Global variables $a and $b are declared in the function, and all reference variables of any variable will point to the global variables. PHP has no limit on the maximum number of global variables that a function can declare. Programmer's home, dedicated to you.



source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template