Backend selection (ADOdb lib)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi list,

I'm writing some code at the moment, and I'm trying to make it as detached as possible from the database used behind. So I already found ADOdb abstraction layer, which I find conienient. But still the fact is that I need to connect to and select a database at the begining of somes script, and the connection to the database are the only thing that remain database-specific. My project has a somewhat classical conf.inc.php file in its root folder and I do database backend select in there. According to the type of backend I generate some php code to be stored in à constant called CONNECTION_CODE which can in turn be passed to the eval() function into the script that need connection to the database can call eval(CONNECTION_CODE) and proceed connected to the database

I'm wondering if this is a decent approach to the abstraction problem, if it features any security risk (I don't like the eval() call) that I've missed. Any suggestion welcome, code sample follows

Thanks folks.

config.inc.php :

/* Database Baclend selection */
/*  Now only MySQL backend is supported */
define("DB_BACKEND","mysql");

/*  Fill out these info if you selected MySQL Backend */
define ("DB_MYSQL_SERVER","");
define ("DB_MYSQL_USER","");
define ("DB_MYSQL_PWD","");
define ("DB_MYSQL_DATABASE","");
switch (DB_BACKEND) {
   case "mysql" :
$connectCode = "\$dbHandle = &ADONewConnection(\"mysql\");\n \$dbHandle->Connect(\"" . DB_MYSQL_SERVER . "\", \"" . DB_MYSQL_USER . "\", \"" . DB_MYSQL_PWD . "\", \"" .
           DB_MYSQL_DATABASE . "\");";
       define("CONNECTION_CODE", $connectCode);
       break;
}

and in any script that needs db connection :

eval(CONNECTION_CODE);
$menuItems = &$dbHandle->Execute('SELECT * FROM yeast_menu0_items');

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux