config file php

<?php

return (object) array(
    'host' => 'localhost',
    'username' => 'root',
    'pass' => 'password',
    'database' => 'db'
);

?>
  This allows you to use the object syntax when you include the php : 
$configs->host instead of $configs['host'].

Also, if your app has configs you need on the client side (like for an Angular app), 
you can have this config.php file contain all your configs 
  (centralized in one file instead of one for JavaScript and one for PHP). 
  The trick would then be to have another PHP file that would echo only the client side 
  info (to avoid showing info you don't want to show like database connection string).
  Call it say get_app_info.php :

<?php

    $configs = include('config.php');
    echo json_encode($configs->app_info);

?>

The above assuming your config.php contains an app_info parameter:

<?php

return (object) array(
    'host' => 'localhost',
    'username' => 'root',
    'pass' => 'password',
    'database' => 'db',
    'app_info' => array(
        'appName'=>"App Name",
        'appURL'=> "http://yourURL/#/"
    )
);

?>
So your database's info stays on the server side, 
but your app info is accessible from your JavaScript, 
with for example a $http.get('get_app_info.php').then(...); type of call.

4
1

                                    &lt;?php
    $servername = 'localhost';
    $username   = 'root'; // Username
    $password   = ''; // Password
    $dbname     = &quot;db_name&quot;;
    $conn       = mysqli_connect($servername,$username,$password,&quot;$dbname&quot;);
    
    if(!$conn){
        die('Could not Connect MySql Server:' .mysql_error());
    }
?&gt;

4 (1 Votes)
0
4
1
A.Ashes 105 points

                                    &lt;?php

return (object) array(
    'host' =&gt; 'localhost',
    'username' =&gt; 'root',
    'pass' =&gt; 'password',
    'database' =&gt; 'db'
);

?&gt;

4 (1 Votes)
0
4
4
Metaphy 90 points

                                    &lt;?php
$config = array(
    &quot;database&quot; =&gt; &quot;test&quot;,
    &quot;user&quot;     =&gt; &quot;testUser&quot;
);

function writeConfig( $filename, $config ) {
    $fh = fopen($filename, &quot;w&quot;);
    if (!is_resource($fh)) {
        return false;
    }
    foreach ($config as $key =&gt; $value) {
        fwrite($fh, sprintf(&quot;%s = %s\n&quot;, $key, $value));
    }
    fclose($fh);

    return true;
}

function readConfig( $filename ) {
    return parse_ini_file($filename, false, INI_SCANNER_NORMAL);
}

var_dump(writeConfig(&quot;test.ini&quot;, $config));
var_dump(readConfig(&quot;test.ini&quot;));

4 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
php config function where is /config.php php parameters from config file php config variable get how to write php config file config.php file set php config directly on code config variables php php config file without php.ini how to create config file in php where php config file is located php config fiel where is config.php how to configure config.php file how to create config.php file for database in php application/config/config.php config.php php php stan config how to add config file in php how to access .config files in php how to store configuration variable in php why we include config.php in our file set config variable php PHP configuration setting file php variable in config php get config from config.php file php.in config php.config file config inc php php define configuration file config php library $config[] in php $config in php php used config file php.ini where to include config.php set up config php file config php php include config file php use config ?ini file with php config config file in php php config( php config files website config phpcs standard way to set variable in config file in php create config page in php how to configur in config.php use Config; php create a config file php where is config.php located php get variable from php config file configuration file example php get variable from config file in php make php config file best way config file in php php config file change php config file save set config php ini php write to config file php how to change config file own config file php config.inc.php example create phpcs config file how to do a config file php how to define configuration values in php how to generate config file in php how to work with config file in php load php config file php import config file include config.php php include config.php where is config.inc.php php config files how to include config file in php how to create config.php file how to create config.php make config file php include config php include config file in php config.inc.php file &quot;config.inc.php&quot; php require config file config php Setting up config File : PHP how to create and get data from config files in php how to get values from config file php php configuration file config in php php config.php /config.php what is config.inc.php php load config file config file in php oops php config file name array in config file php php read config file simple php database config file in php config gile php create config.php How to best config you main php file php.ini setup php save settings to file php config() how i can create config file php do i need web.config file php config.php code phpstorm config file how to make a config file php when i inlclude config file dataconenction dont work php php ini path on rrot create configuration php file using phpcode php settings config.inc.php handle config file in php php ini file phpcs config activate php ini define() vs config file php php configuration files create a config file php poseidon set up a config file php on local host set up config file php on local host php.ini config server php create one config.php what is configuration.php.tf file config.in.php php create configuration file create php config file get config() in php where to config config.ini.php config file for php application config.php php $config config file for php config.php example settings file php where to put your own config file in php rpoject php custom configuration file php common config file config file php php use config file recommended for configuration file in php config for php how to read from config php config:: php php big projects configuration file specify creation of configuration on first run php creating config file and editing using php page create config value file in php create config file in php php web application configuration file configuration file in php websites php create config file and include where can i put the config file php php read config file example how to make config file for php php simple config file php-config create config file in php for sess_database create config file in php for database the best way to create a config file in php add conf file to php php create config file php load config from separate file create configuration file php config file php example php make a local config file php make a config file make a php config gile php config file php config
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source