Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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());
    }
?>
Comment

how to make a config file for php

<?php

$server = "localhost";
$username = "root";
$password = "";
$db = "your_db_name";


$conn = mysqli_connect($server, $username, $password, $db);

if(!$conn){
    die('Error in connecting to server or Database: ');
}
Comment

config file php

<?php

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

?>
Comment

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.
Comment

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
", $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"));
Comment

php config file

<?php
 
/*
 * All database connection variables
 */
 
define('DB_USER', "root"); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', "androidhive"); // database name
define('DB_SERVER', "localhost"); // db server
?>
Comment

config in php

<?php 

$servername = "localhost";
$username = "root";
$password = "";

try {
  $conn = new PDO("mysql:host=$servername;dbname=crud", $username, $password);
} catch(PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
  exit();
}

$errors = ['result' =>'', 'email'=>'', 'password'=>'', 'login'=>'', 'signup'=>''];

session_start();

require('controllers/contacts-controller.php');

require('controllers/auth-controller.php');





?>
Comment

PREVIOUS NEXT
Code Example
Php :: Toaster switch Statement 
Php :: php capture include 
Php :: php print string as bytes 
Php :: kill php-fpm inside docker 
Php :: truncate url rewrites magento 2 database 
Php :: put the date from new york with php 
Php :: php namespaces 
Php :: audio validation in jquery validation 
Php :: wp menu declaration 
Php :: laravel migration drop foreign keys 
Php :: where statement multiple argument in codeigniter 
Php :: laravel get data from model to controller 
Php :: php move in array 
Php :: php while select query 
Php :: php date text in middle 
Php :: last index of array in laravel 
Php :: 1 to many relationship in laravel 
Php :: wordpress add submenu under custom post type 
Php :: laravel model create get id 
Php :: php fpdf in phpmailer 
Php :: link title to blog post wordpress in the loop 
Php :: dropdown search php mysql 
Php :: Define memory limit in PHP 
Php :: laravel How to include model attribute automatically 
Php :: laravel 8 search with pagination 
Php :: php unix socket client 
Php :: magento 2 laravel valet 502 bad gateway 
Php :: Passing values to blade using redirect() and back() functions 
Php :: Using $this when not in object context 
Php :: parseint php 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =