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.
1<?php
2
3return (object) array(
4 'host' => 'localhost',
5 'username' => 'root',
6 'pass' => 'password',
7 'database' => 'db'
8);
9
10?>
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"));
1<?php
2 $servername = 'localhost';
3 $username = 'root'; // Username
4 $password = ''; // Password
5 $dbname = "db_name";
6 $conn = mysqli_connect($servername,$username,$password,"$dbname");
7
8 if(!$conn){
9 die('Could not Connect MySql Server:' .mysql_error());
10 }
11?>
12
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