Problem
I'm using $GLOBALS[]
variable to define names of tables from DB in my php files to make it simple changing names of tables and for general mobility/comfort. BUT..
I've heard that using $GLOBALS[]
is SOMEHOW bad or something..
So, it's happening like this:
Tables in Database
Users
Orders
Products
Actually there are 10-20 tables...
global_vars.php
<?php
$GLOBALS['t_users'] = 'Users';
$GLOBALS['t_users'] = 'Orders';
$GLOBALS['t_users'] = 'Products';
//...
//etc.
?>
Now, when I need to access DB from different pages of website and with different purposes I do it like so:
function GetUsers(){
$sql = "SELECT * FROM $GLOBALS[t_users]";
// ...execute
}
function Get_OneUser($id){
$param['id'=>$id];
$sql = "SELECT * FROM $GLOBALS[t_users] WHERE id=:id";
// ...etc
}
function Get_Orders(){
$sql = "SELECT * FROM $GLOBALS[t_orders]";
// ...etc
}
function Get_OrdersB(){
$sql = "SELECT * FROM $GLOBALS[t_orders] WHERE id=:id";
// ...etc
}
function Get_Products(){
$sql = "SELECT * FROM $GLOBALS[t_products]";
// ...etc
}
// -- AND SO ON, AND SO ON........
Imagine, one day I will need to rename tables/change database. Then (with this structure) I can only change one line in global_vars.php.. It will be perfect!
General Question
What could be a better way to make it?
Why this is/isn't good/bad? Help me figure it out! Thanks!