create config value file in php

Solutions on MaxInterview for create config value file in php by the best coders in the world

showing results for - "create config value file in php"
Amy
01 Feb 2016
1<?php
2
3return (object) array(
4    'host' => 'localhost',
5    'username' => 'root',
6    'pass' => 'password',
7    'database' => 'db'
8);
9
10?>
11  This allows you to use the object syntax when you include the php : 
12$configs->host instead of $configs['host'].
13
14Also, if your app has configs you need on the client side (like for an Angular app), 
15you can have this config.php file contain all your configs 
16  (centralized in one file instead of one for JavaScript and one for PHP). 
17  The trick would then be to have another PHP file that would echo only the client side 
18  info (to avoid showing info you don't want to show like database connection string).
19  Call it say get_app_info.php :
20
21<?php
22
23    $configs = include('config.php');
24    echo json_encode($configs->app_info);
25
26?>
27
28The above assuming your config.php contains an app_info parameter:
29
30<?php
31
32return (object) array(
33    'host' => 'localhost',
34    'username' => 'root',
35    'pass' => 'password',
36    'database' => 'db',
37    'app_info' => array(
38        'appName'=>"App Name",
39        'appURL'=> "http://yourURL/#/"
40    )
41);
42
43?>
44So your database's info stays on the server side, 
45but your app info is accessible from your JavaScript, 
46with for example a $http.get('get_app_info.php').then(...); type of call.
Giulia
24 Jan 2017
1<?php
2
3return (object) array(
4    'host' => 'localhost',
5    'username' => 'root',
6    'pass' => 'password',
7    'database' => 'db'
8);
9
10?>
Mateo
24 Sep 2017
1<?php
2$config = array(
3    "database" => "test",
4    "user"     => "testUser"
5);
6
7function writeConfig( $filename, $config ) {
8    $fh = fopen($filename, "w");
9    if (!is_resource($fh)) {
10        return false;
11    }
12    foreach ($config as $key => $value) {
13        fwrite($fh, sprintf("%s = %s\n", $key, $value));
14    }
15    fclose($fh);
16
17    return true;
18}
19
20function readConfig( $filename ) {
21    return parse_ini_file($filename, false, INI_SCANNER_NORMAL);
22}
23
24var_dump(writeConfig("test.ini", $config));
25var_dump(readConfig("test.ini"));
Lilian
21 Nov 2020
1<?php
2 
3/*
4 * All database connection variables
5 */
6 
7define('DB_USER', "root"); // db user
8define('DB_PASSWORD', ""); // db password (mention your db password here)
9define('DB_DATABASE', "androidhive"); // database name
10define('DB_SERVER', "localhost"); // db server
11?>
12
queries leading to this page
settings file phphow to write php config filephp settingsconfig phpphp configphp config phpphp custom configuration filephpstorm config filecreate config file in phpphp read config file exampleset php config directly on code 24config phpphp ini setuphow to make a config file phpload php config filephp get config from config php filephp in configphp config fiel 2fconfig phpinclude php file config config gile phpphp confighow to store configuration variable in phpphp web application configuration filephp create config file and includephp 24configphp make a local config filephp load config filehow to do a config file phpuse config 3b phpphp config 28php use config 3finicreate a config file php poseidonsetup config phpphp variable in configphp config settingsphp parameters from config fileapplication 2fconfig 2fconfig phphow to work with config file in phpfile config phpwhere is 2fconfig phpconfig 3a 3a phpwhere is config inc phphow to define configuration values in phparray in config file phpdo i need web config file phpstandard way to set variable in config file in phphow to create config file in phpcreating config file and editing using php pageown config file phpconfig php filephp config file nameset up a config file php on local hostwhen i inlclude config file dataconenction dont work phpwhat is config inc phphow to get values from config file phpconfig php in phpphp ini path on rrotconfig 2fconfig phphow to create php config file php include configphp configuration fileconfig php packagephp specify config filehow to configur in config phpmake php config filecreate phpcs config filephp config files websiteinclude config php php 22config inc php 22create config phpphp create config fileconfig php codecreate php config filephp import config filehow to set config file for php in serverconfig database php examplewhy do we need config phpconfig inc php fileconfig php libraryhow to read from config phpconfig file in php oopsconfig php phpspecify creation of configuration on first run phpconfig inc phpphp define configuration fileget variable from config file in phpphp used config file php inimake config file phpcreate one config phpwhat is configuration php tf file configuration file in php websites 24config 5b 5d in phpphp config file savephp common config fileconfig variables phpactivate php iniphp make a config filehow to configure config php filerecommended for configuration file in phphow to create config phpsimple php database config file in phpphp config 28 29create config file in php for databasewhere is config php locatedconfig for phpconfig file for php applicationconfig file php exampleconfig in phpwhere php config file is locatedconfig phpcsconfig php exampleconfig function in phpwhy we include config php in our filehow to generate config file in phpwhere is config phpfile with php configget config 28 29 in phpwhere to config config ini phpphp get config valuesconfig file for phpphp ini filecreate configuration php file using phpcodeconfig in phpphp require config filephp read config fileinclude config phpbest way config file in phpphp config variable getphp config files handle config file in phpcreate config file in php for sess databasemake a php config gileset config variable phpphp how to change config filehow i can create config file phpdefine 28 29 vs config file phpcreate config value file in phpwhere to include config phpphp load configphp simple config fileconfig method phpphp config file without php iniwhere is php config fileset up config file php on local hostthe best way to create a config file in phpconfig file in phpphp write to config filehow to make config file for phpphp config filephp big projects configuration fileconfig phpset config php inihow to add config file in phpconfig inc phpconfig server phpconfig file phpinstructions config inc phpwhere to put your own config file in php rpoject php configuration filesphp create configuration filephp config methodhow to access config files in phphow to best config you main php fileadd conf file to phpcreate configuration file phpconfig inc php examplephp include config filecreate a config file phpwhat is config php filephp iniphp load config from separate filehow to include config file in phpconfiguration file example phpphp config filewhere can i put the config file phpphp use config file phpcs configsetting up config file 3a phpphp config file changephp set config in code 24config in phphow to create config php fileset up config phpconfig 28 29 in phphow to create and get data from config files in phpinclude config file in phpphp get variable from php config filedefault php config filephp save settings to fileinclude config phpphp config functioncreate config value file in php