get server config? repetitive boring work

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

get server config? repetitive boring work

Post by D Oliveira » 2019-09-03 23:16

Can anyone share a way of passing global variables? is there a way for me to get the server config from config.php to initiate db connection? I have several fpdf outputs and so when i use my local server this is what one of the files look like

Code: Select all

$con = mysqli_connect('localhost','root','');
mysqli_select_db($con,'coachrubens');

//get medidas data

set_time_limit(0);

ini_set('memory_limit', '-1');

$getvariable = $_GET['id'];

$query0 = mysqli_query($con,"select * from medidascomp where ID= '{$getvariable}'");
$medidas0 = mysqli_fetch_array($query0);
and when i upload to the server is :

Code: Select all

$con = mysqli_connect('localhost','user','pass');
mysqli_select_db($con,'onlinedb');

//get medidas data

set_time_limit(0);

ini_set('memory_limit', '-1');

$getvariable = $_GET['id'];

$query0 = mysqli_query($con,"select * from medidascomp where ID= '{$getvariable}'");
$medidas0 = mysqli_fetch_array($query0);

and so I have to replace the following code for 25 files.

Code: Select all

$con = mysqli_connect('localhost','user','pass');
mysqli_select_db($con,'onlinedb');


Is there a way to retrieve that info with global variables? user, pass, and dbname

thank you

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: get server config? repetitive boring work

Post by D Oliveira » 2019-09-04 01:52

solution:

Code: Select all


require ('config.php');

//db connection
$con = mysqli_connect($dbServer, $dbUsername, $dbPassword);
mysqli_select_db($con,$dbDatabase);


User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: get server config? repetitive boring work

Post by baudwalker » 2019-09-04 04:46

yes your correct, I do simalar to you but I have a login.php file that contains the include it in any file that uses the db.

<?php
require ('data/config.php');

// Create connection
$conn = new mysqli($dbServer, $dbUsername, $dbPassword, $dbDatabase);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

//echo"Connected successfully";
?>

Barry

Post Reply