i finally figured out how to access an external database with DBConnectionStack.
so i set up DB 'external1' in config/config.php and tried to access it in a module like this:
in this case the gallery DB to count photoitems:
Code
DBConnectionStack::init('external1');
$g2 = DBUtil::selectObjectCount ('g2_PhotoItem');
DBConnectionStack::popConnection();
$g2 = DBUtil::selectObjectCount ('g2_PhotoItem');
DBConnectionStack::popConnection();
now this is the error im getting:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
SELECT COUNT( 1) FROM
Exit-Handler: Exiting after SQL-error
Stacktrace:
1. (array) 0:
1. (string) file = /var/www/portal/includes/pnobjlib/DBUtil.class.php
2. (integer) line = 124
3. (string) function = pn_exit
4. (array) args:
1. (string) 0 = Exiting after SQL-error
2. (array) 1:
1. (string) file = /var/www/portal/includes/pnobjlib/DBUtil.class.php
2. (integer) line = 1062
3. (string) function = executeSQL
4. (string) class = DBUtil
5. (string) type = ::
6. (array) args:
1. (string) 0 = SELECT COUNT( 1) FROM
3. (array) 2:
1. (string) file = /var/www/portal/modules/Bestand/pnadminapi.php
2. (integer) line = 372
3. (string) function = selectObjectCount
4. (string) class = DBUtil
5. (string) type = ::
6. (array) args:
1. (string) 0 = g2_PhotoItems
[...]
Table 'gallery2.pn_session_info' doesn't exist
UPDATE pn_session_info SET pn_ipaddr= [...]
i didnt want to post the whole stacktrace, but it seems the DB connections are getting mixed up.
so i played around with selectobjectcount a little further, like this (note that table 'users' doesnt exist in the gallery2 database 'external1'):
Code
DBConnectionStack::init('external1');
$g2 = DBUtil::selectObjectCount ('users');
DBConnectionStack::popConnection();
$g2 = DBUtil::selectObjectCount ('users');
DBConnectionStack::popConnection();
with the error:
Table 'gallery2.pn_users' doesn't exist
SELECT COUNT( 1) FROM pn_users
Exit-Handler: Exiting after SQL-error
Stacktrace:
[...]
still with the Table "'gallery2.pn_session_info' doesn't exist [...]" in the stacktrace.
somehow there seems to be a problem with prefixes. but actually i have no idea!
can anyone help? thx :)
ps: postnuke rocks
edit: im using pn0.8-RC1 with PHP 5.2.3 and mysql 5.0.41
edited by: philipp2, Jul 29, 2007 - 02:00 PM
