Backend selection (ADOdb lib)

From: Date: Thu, 02 Mar 2006 20:33:49 +0000
Subject: Backend selection (ADOdb lib)
Groups: php.general 
Request: Send a blank email to php-general+get-231365@lists.php.net to get a copy of this message
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');

« previous php.general (#231365) next »