Open In App

How to import config.php file in a PHP script ?

The include statement in PHP copies the code of text from the file mentioned, into the file that uses the include statement. It directs the preprocessor to insert the content specified into the following program. The name of the file to be included is written in double-quotes. It is a good practice to write the basic database details and user details in a file named “config.php”. You can also include the connection building statements in the config.php file to automatically build the connection to the database for every page that includes the config.php file. Including files allows you to form a template of code that is required by multiple pages of a website.

Syntax:



<?php
   include('config.php');
?>

Example 1: This shows the creation and including of config.php file.

Example 2: If you want to save the contents of the config.php file into a variable, then the following code does that work.




Article Tags :