php configuration
phpinfo();
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.
how to create config file in php
<?php
$servername = 'localhost';
$username = 'root'; // Username
$password = ''; // Password
$dbname = "db_name";
$conn = mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect MySql Server:' .mysql_error());
}
?>
config file php
<?php
return (object) array(
'host' => 'localhost',
'username' => 'root',
'pass' => 'password',
'database' => 'db'
);
?>
create config value file in php
<?php
$config = array(
"database" => "test",
"user" => "testUser"
);
function writeConfig( $filename, $config ) {
$fh = fopen($filename, "w");
if (!is_resource($fh)) {
return false;
}
foreach ($config as $key => $value) {
fwrite($fh, sprintf("%s = %s\n", $key, $value));
}
fclose($fh);
return true;
}
function readConfig( $filename ) {
return parse_ini_file($filename, false, INI_SCANNER_NORMAL);
}
var_dump(writeConfig("test.ini", $config));
var_dump(readConfig("test.ini"));
wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
/** MySQL hostname */
define('DB_HOST', 'localhost');
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us