-1

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.

Deo
  • 681
  • 1
  • 6
  • 15

1 Answers1

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