I'm wondering if there is a way to save a certain settings of my php(ex. phpMyAdmin credentials) by not opening the code. Simply inserting the credential in a textbox and then saving it. This would really help if I'm going to deploy it and don't need to open the code to change the setting/credentials.
Asked
Active
Viewed 229 times
-1
-
save credentials in a file like` database.php` as an array and use include `database.php ` to load it at the top – Jason Joslin May 02 '17 at 03:02
-
yes,it can. you just save it in php.file – Mattia Dinosaur May 02 '17 at 03:06
-
http://stackoverflow.com/a/14952941/6229548 – Mattia Dinosaur May 02 '17 at 03:07
-
Ok I know this method, what I want is that I don't have open any php file, just input it in the GUI and then save the inputed data to the php file.. – Deo May 02 '17 at 04:11
1 Answers
2
If you store it in its own class you can access it in a method that retrieves the config from the property
// database.php
<?php
class Database{
private $config = [
'user' => 'root',
'password' => '',
'database' => my_db
];
public function getConfig(){
return $this->config;
}
};
Then in your php file that renders a page
//index.php
<?php
...
include database.php
$database = new Database();
$config = $database->getConfig();
...
A more ideal usage you would actually call $database->getConnection();
Which would contain the code to build your PDO or mysqli connection object and return it.

Jason Joslin
- 1,154
- 8
- 23