mysql - How to Auto Reload the php file content usgin php? -


i have database config file pdo connection (config.php).this content of file.

$db_host = "localhost";     $db_name = "my_database_name";//@ line dynamically adding     $db_user = "root";     $db_pass = "";       // @connecting database above credentials     try{         $db_conn = new pdo("mysql:host={$db_host};dbname={$db_name}", $db_user, $db_pass);         $db_conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);     }catch(pdoexception $e){         echo $e->getmessage();     } 

i adding $db_name = "my_database_name"; line using script.and using database name crud operation.but config.php file showing notice: undefined variable: db_name in f:\xampp\htdocs\rootfolder\config\config.php on line 7 per knowledge issue because of adding $db_name dynamically.so if auto reload config.php php file work.how auto reload php file can please me on this.

if wrap contents of config file in function (or better class go oop). can call function name database name whenever want. returning connection you'll have right connection.

application.php

require_once('db.php'); $conn1 = getdbconnection('db1'); // stuff on db1  $conn2 = getdbconnection('db2'); // stuff on db2 (or db1 since still open) 

db.php

function getdbconnection($db_name) {     // make connection     return $db_connection; } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -