Fork me on GitHub

DBConnectionStack and DBUtil::selectObjectCount  Bottom

  • hi,
    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();


    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();


    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
  • Interesting ... I think the 1st error you're reporting is because PN doesn't know about g2_PhotoItem (in terms of it being registered in the pntables structure). Even if you access an external DB, you need to provide PN with the matching pntables structure so that it knows how to build the query ...

    The 2nd error I don't know off the top of my head. Can you tell me exactly which PhotoGallery you have installed so that I can try to reproduce this?

    Greetings/Thanks
    R
  • hi,
    sorry for the late reply. i have been quite busy in the past, and now im in my holidays, somehow.
    i understand, that i have to define the table definition for the external DB. but honestly, i didnt investigate any further yet.
    but for completeness, i was using the latest menalto gallery2 application and its database.
    anyway, thank you very much for your effort/help. i promise to check this out at a later point =)
    thx
    philipp
  • OK, thanks. Let me know how it goes ...

    Greetings
    R

This list is based on users active over the last 60 minutes.