Fork me on GitHub

Creating tables using dbutil  Bottom

  • The latest daily SVN snapshot produces fixes for the add module issue. The missing id is now signed and I was able to add modules in an normal fashion.

    I'm converting a module I made for the new PN 0.8 standard, but are not sure what the "official" method for calling and activing DB are for writing and reading. Any suggestions are appriciated.( I just like to get close to the standard. )
  • aase,

    See Database access using DBUtil. Feel free to improve & extend the docs as you write your code.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • hi again,

    I actually used the DBUtil version in my first attempt, but only got table creation failed. I just tried the sample given in the Wiki with the same results.

    I tried a simple version just creating the table (no content) and got this error

    Exit-Handler: DBUtil::createTable: neither the SQL parameter nor the pntable array contain the ADODB dictionary representation of table to create...

    It may look to me that the problem is me trying to add this module inside the modules folder and somehow this generate a conflict.

    Any suggestions?

  • As indicated by the error message you need to either pass the createTable method a valid SQL string (in ADODB data dictionary format) or have the same information in pntables.php.

    Check out how some of the existing modules work for some sample code.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Hi Mark,

    I'm aware of that. And the samples have been according to samples given in the Wiki.

    like:

    Code

    $sql = "id      I      NOTNULL AUTO PRIMARY,
                title   C(255) NOTNULL DEFAULT '',
                content C(255) NOTNULL DEFAULT '',
                online  L   NOTNULL DEFAULT 0"
    ;

        if (!DBUtil::createTable('test_table', $sql)) {
            pnSessionSetVar('errormsg', _CREATETABLEFAILED);
            return false;
        }


    What I ment in the last post is that

    Code

    if (!DBUtil::createTable('test_table')) {
            pnSessionSetVar('errormsg', _CREATETABLEFAILED);
            return false;
        }


    should be able to create a table named 'test_table'.

    For some strange reason none of this works.

    PHP 5+
    SQL 4+
    PN last SVN snapshot
    Folder with pninit.php (modules/test/pninit.php)

    Error is allways table creation failed.
  • In the latter example you *must* have the full table definition in pntables.php. The Wiki only gives an example of the table definiton in pninit.php but there is another method.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • k, well the first sample should work... without any definitions made in pntables as well.

    I notice DBUtil is used in the system modules. For the pnaddons modules the old dbcall method is used.

    Ofcourse I can go back to the old method, but it is better to walk the same path as PN I guess;)
  • The first example should work provided the standard table entries in pntables.php are correct. The value addons haven't been updated yet but will be.

    Send me across your module to markwest at postnuke dot com and i'll take a look.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • 0 users

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