I am writing a simple PHP script that make use of DB to export some products. My code starts like
$host = "localhost";
$user = "";
$pass = "";
$database = "";
letting user to add those info. However is there any way to make use configuration.php file that it is saved in the same directory
What I did is this but I didn’t got any result
require('configuration.php');
echo $user;
This is the configuration.php file
<?php
class JConfig {
var $dbtype = 'mysql';
var $host = 'localhost';
var $user = 'user';
var $password = 'pass';
var $db = 'db';
}
?>
If you use a class for the configuration (why ?) then you have to initialize it. or use static class vars.
you could also use just defines e.g
after include/requiring it, you just do:
Reference : http://php.net/manual/en/language.oop5.static.php
EDIT: after your edit i think you mean something diffrent.
you will need 2 config files.
config_default.php
config.php
users write their config in config.php you have yours in config_default.php
you will have to include config_default.php first and than config.php. be notet this only works with variables. if you use classes you will have to write code to init the classes with the correct configuration variables.