Multi grids sql settings handling

Talk about programming tricks and examples

Moderator: alexandrleonenko

Posts: 102
Joined: Sep 13th, '10, 14:31
Location: Metz, France

Multi grids sql settings handling

Postby lambro » May 14th, '11, 08:11

Hi !
Sometimes you can have several datagrids for a single site. What happens when you change sql settings (for testings or backup reasons)? You end up copy/pasting your settings in all of them.
A good way to make it waaayyyyyyyyyy easier is to use this code at the beginning of your dg file :

Code: Select all

$Arrval = dgtablepointer();

instead of

Code: Select all

   //  $DB_USER='name';            /* usually like this: prefix_name             */
    //  $DB_PASS='';                /* must be already encrypted (recommended)    */
    //  $DB_HOST='localhost';       /* usually localhost                          */
    //  $DB_NAME='dbName';          /* usually like this: prefix_dbName           */

The function reads as such and will simply do the copy/paste for you in all the grids. You can define it in file and "require_once"(it) at the beginning of each of your dg file, preferably before creating the dg object.
function :

Code: Select all

function dgtablepointer(){
$Arrval = array ($DB_USER,$DB_PASS,$DB_HOST,$DB_NAME);

Hope it helps! @+

Return to “Programming Tricks”