please help me, problem with MDB2 and DB_DataObject, wrong prefixed database name in select statement

From: Date: Wed, 13 Jun 2007 07:14:02 +0000
Subject: please help me, problem with MDB2 and DB_DataObject, wrong prefixed database name in select statement
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-27462@lists.php.net to get a copy of this message
Dear Sir, Madam My name is Phung Ngoc Hieu. I am working for Dirox company in Vietnam. My company was using DB and DB_DataObject (version 1.8.5). Yesterday, I was assigned to upgrade DB to MDB2. And I ran into this problem: I have table Annouceur in database REGIEPUB2_DEV_USERS.When I selected all data from Annouceur, I got this: Annonceur: ERROR: MDB2_Error Object ( [error_message_prefix] => [mode] => 1 [level] => 1024 [code] => -18 [message] => MDB2 Error: no such table [userinfo] => _doQuery: [Error message: Could not execute statement] [Last executed query: SELECT * FROM ANNONCEUR WHERE ( ANNONCEUR.ID_AGENT = 0 ) ] [Native code: 1146] [Native message: Table 'ADSERVER_DEV.ANNONCEUR' doesn't exist] [connection] => Resource id #33 [opened_persistent] => [database_name] => REGIEPUB2_DEV_USERS [connected_database_name] => REGIEPUB2_DEV_USERS [connected_server_info] => 5.0.18-Debian_3.dotdeb.1-log I don't know why Annonceur is prefixed with ADSERVER even its database name (REGIEPUB2_DEV_USERS) is specified correctly. Following is a part of the content of my configuration.php define("DATABASE_MAIN_SERVER", "xxx"); define("DATABASE_MAIN_NAME", "ADSERVER_DEV"); define("DATABASE_MAIN_LOGIN", "xxx"); define("DATABASE_MAIN_PASSWORD", "xxx"); define("DATABASE_USERS_SERVER", "xxx"); define("DATABASE_USERS_NAME", "REGIEPUB2_DEV_USERS"); define("DATABASE_USERS_LOGIN", "xxx"); define("DATABASE_USERS_PASSWORD", "xxx"); ................ $options = &PEAR::getStaticProperty( 'DB_DataObject', 'options' ); $options = array( 'database_'.DATABASE_MAIN_NAME => DATABASE_MAIN_CONNECTION_STRING, 'database_'.DATABASE_USERS_NAME => DATABASE_USERS_CONNECTION_STRING, 'schema_location' => ADSERVER_DIR.'/class/PEAR/DataObjects', 'class_location' => ADSERVER_DIR.'/class/PEAR/DataObjects', 'require_prefix' => ADSERVER_DIR.'/class/PEAR/DataObjects', 'class_prefix' => 'DataObjects_', 'auto_quote' => 'off', 'db_driver' => "MDB2", ); And my class ANNONCEUR class DataObjects_ANNONCEUR extends DB_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ public $__table = 'ANNONCEUR'; // table name public $_database = 'REGIEPUB2_DEV_USERS'; // database name (used with database_{*} config) public $ID; // int(11) not_null primary_key auto_increment public $ID_LOGIN_MASTER; // int(11) not_null; public $ID_AGENT; // int(11) not_null public $NOM; // string(255) not_null /* Static get */ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_ANNONCEUR',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE } To make a quick fix, I added the following code into file DataObject.php, function find( ) (line 418 to 430) // hieu added prefix database name for MDB2 if ((isset($_DB_DATAOBJECT['CONFIG']['db_driver'])) && ($_DB_DATAOBJECT['CONFIG']['db_driver'] == 'MDB2')) { $dbPrefix = ''; if (strlen($this->_database) && in_array($DB->dsn['phptype'],array('mysql','mysqli'))) { $dbPrefix = ($quoteIdentifiers ? $DB->quoteIdentifier($this->_database) : $this->_database) . '.'; } $objTable = $dbPrefix . $objTable; } // end hieu However, I don't think this solution is good. Would you please help me with this problem? Maybe I missed something during migrating DB to MDB2. Thank you very much for your help. Best Regards, Phung Ngoc Hieu

« previous php.pear.general (#27462) next »