Fork me on GitHub

Watch

GitHub Core

Show your support for Zikula! Sign up at Github account and watch the Core project!




GitHub Modules

Forum Activity

Forum feed

» Visit forum | » View latest posts

Development Question  Bottom

  • I'm working on my Recipe Module again, trying to get the init to work.. I'm only doing one table at the moment, to figure out the problem. I've been staring at the code for awhile now and I keep getting a DB failed.

    Here's the pntables.php code

    Code

    function $PostChef_pntables()
    {
            // Initialise table array
            $pntable = array();

            // Name for Categories database entities
            $PostChef = pnConfigGetVar('prefix') . '_postchef_categories';

            // Table name
            $pntable['postchefcategories'] = $PostChef;

            // Column names
            $pntable['postchef_categories'] = array('catid' => $PostChef . '.catid',
                'short' => $PostChef . '.short',
                'long' => $PostChef . '.long');
            // Return the table information
            return $pntable;
    }


    And the pninit.php init function

    Code

    function PostChef_init() {
            list($dbconn) = pnDBGetConn();
            $pntable = pnDBGetTables();

            $postchefcategoriestable    = $pntable['postchefcategories'];
            $postchefcategoriescolumn   = &$pntable['postchef_categories'];

            $sql = "CREATE TABLE $postchefcategoriestable (
                $postchefcategoriescolumn[catid] tinyint(3) NOT NULL auto_increment,
                $postchefcategoriescolumn[short] varchar(32) NOT NULL default '',
                $postchefcategoriescolumn[long] longtext NOT NULL default '',
                PRIMARY KEY (catid))"
    ;
            $dbconn->Execute($sql);

            if ($dbconn->ErrorNo()  != 0) {
                pnSessionSetVar('errormsg', $sql);
                return false;
            }

     }


    I modified the error trap to give me the $SQL statement as you can see, and it's not getting any of the variables.

    Right now the module is striped down to just these two files, no point continuing until I can create the database.
  • You shouldn't use the '$' in the function declaration. Also, you can try and load the PHP file directly to see if it compiles:

    http://www.<yoursite>.com/modules/<modname>/pninit.php</modname></yoursite>
  • I would also change:

    Code

    pnSessionSetVar('errormsg', $sql);


    to

    Code

    pnSessionSetVar('errormsg', $dbconn->ErrorMsg());


    to get a more detailed error message.
  • chrisabruce

    You shouldn't use the '$' in the function declaration.


    DOH, how did I not see that, and even more important, how did I make that mistake in the first place? I've been doing some degree of programing for a decade between C/C++ & PHP

    As to the error message, I generally like to see what the SQL statement is when I have problems, so that's why I changed it to that from the normal code.

    Yep, that $ was the problem. Someone needs to write an app to take a MySQL dump and create those two files on the fly.

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