- Moderated by:
- Support
-
- rank:
-
Freshman
- registered:
- July 2003
- Status:
- offline
- last visit:
- 17.07.03
- Posts:
- 4
Sorry if this sort of thing has been posted before but here it is. When I initialize my module essentially nothing happens. I run initialize and it displays initialization successful yet the DB tables have not been created. Here are my pninit and pntables files respectively, hopefully someone can tell me the problem
pninit.php
Code
function Rules_init()
{
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn()
// we currently just want the first item, which is the official
// database handle. For pnDBGetTables() we want to keep the entire
// tables array together for easy reference later on
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// It's good practice to name the table and column definitions you
// are getting - $table and $column don't cut it in more complex
// modules
$rulestable = $pntable['rules'];
$rulescolumn = &$pntable['rules_column'];
// Create the table - the formatting here is not mandatory, but it does
// make the SQL statement relatively easy to read. Also, separating out
// the SQL statement from the Execute() command allows for simpler
// debug operation if it is ever needed
$sql = "CREATE TABLE $rulestable (
$rulescolumn[rid] int(10) NOT NULL auto_increment,
$rulescolumn[rulenumber] int(3) NOT NULL default 0,
$rulescolumn[rulecategory] int(2) NOT NULL default 0,
$rulescolumn[ruletext] blob NOT NULL,
PRIMARY KEY($rulescolumn[rid]))";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _CREATETABLEFAILED);
return false;
}
// Set up for second table
$rulescategorytable = $pntable['rules_categories'];
$rulescategorycolumn = &$pntable['rules_categories_column'];
//Create the second table
$sql = "CREATE TABLE $rulescategorytable (
$rulescategorycolumn[cid] int(10) NOT NULL auto_increment,
$rulescategorycolumn[catnumber] int(3) NOT NULL default 0,
$rulescategorycolumn[catname] varchar(100) NOT NULL default '',
PRIMARY KEY($rulescategorycolumn[cid]))";
$dbconn->Execute($sql);
//Check for an error with the database code, and if so set an
appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
//pnSessionSetVar('errormsg', _CREATETABLEFAILED);
//return false;
}
// Initialisation successful
return true;
}
/**
* upgrade the template module from an old version
* This function can be called multiple times
*/
function Rules_upgrade($oldversion)
{
// Upgrade dependent on old version number
switch($oldversion) {
case 1.0:
// Code to upgrade from version 1.0 goes here
break;
case 2.0:
// Code to upgrade from version 2.0 goes here
break;
}
// Update successful
return true;
}
/**
* delete the template module
* This function is only ever called once during the lifetime of a particular
* module instance
*/
function Rules_delete()
{
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn()
// we currently just want the first item, which is the official
// database handle. For pnDBGetTables() we want to keep the entire
// tables array together for easy reference later on
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// Drop the table - for such a simple command the advantages of separating
// out the SQL statement from the Execute() command are minimal, but as
// this has been done elsewhere it makes sense to stick to a single method
$sql = "DROP TABLE $pntable[rules]";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
// Report failed deletion attempt
return false;
}
// Drop the second table
$sql = "DROP TABLE $pntable[rules_categories]";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
// Report failed deletion attempt
return false;
}
// Deletion successful
return true;
}
pntables.php
Code
<?php
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WIthOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Carl Uussalu
// Purpose of file: Table functions for rules module
// -
/**
* This function is called internally by the core whenever the module is
* loaded. It adds in the information
*/
function Rules_pntables()
{
// Initialise table array
$pntable = array();
// Get the name for the template item table. This is not necessary
// but helps in the following statements and keeps them readable
$rules= pnConfigGetVar('prefix') . '_rules';
// Set the table name
$pntable['rules'] = $rules;
// Set the column names. Note that the array has been formatted
// on-screen to be very easy to read by a user.
$pntable['rules_column'] = array('rid' => $rules . '.pn_rid',
'rulenumber' => $rules . '.pn_rulenumber',
'rulecategory' => $rules . '.pn_rulecategory',
'ruletext' => $rules . '.pn_ruletext');
// Get the name for the template item table. This is not necessary
// but helps in the following statements and keeps them readable
$rules= pnConfigGetVar('prefix') . '_rules_categories';
// Set the table name
$pntable['rules_categories'] = $rules;
// Set the column names. Note that the array has been formatted
// on-screen to be very easy to read by a user.
$pntable['rules_categories_column'] = array('cid' => $rules . '.pn_cid',
'catnumber' => $rules . '.pn_catnumber',
'catname' => $rules . '.pn_catname');
// Return the table information
return $pntable;
}
?> -
- rank:
-
Moderator
- registered:
- March 2002
- Status:
- offline
- last visit:
- 26.08.08
- Posts:
- 7720
@infopro It's a coding question... I'll field this one.
@destruct It's fairly difficult to read code of the forums. What I would do as a debug is to put an echo $SQL after each SQL statement is formed. This will give you the SQL that is being executed. This will allow you to either spot an instant problem with the pntables array or your forming of the SQL. If you can't spot anything at this stage then you've got the SQL so paste this into phpMyAdmin and you may get some extra information here.
-Mark
-Mark -
- rank:
-
Steering Committee
- registered:
- December 2002
- Status:
- offline
- last visit:
- 02.12.08
- Posts:
- 13418
-Mark
-Mark
????
didnt know you were skitzophrenic mate ;)
--
Regards,
Simon
itbegins.co.uk - Zikula Consulting
Please read the Support Guide -
- rank:
-
Freshman
- registered:
- July 2003
- Status:
- offline
- last visit:
- 17.07.03
- Posts:
- 4
Well I had tried that Mark but the problem was I wasn't getting an error, it was telling me it was initializing just fine although tables weren't appearing. I figured out problem was I missing the // on a line which should have been commented and that at least got me to the stage where I could view the SQL. I player around with the SQL and fgiured out that this line:
Code
was causing me problems. I changed it to:
Code
And it worked fine. What I do find confusing is that before making this change, the SQL statement was executing just fine in phpMyAdmin but it just wouldn't work on site. WOnder why that is. -
- rank:
-
Moderator
- registered:
- March 2002
- Status:
- offline
- last visit:
- 26.08.08
- Posts:
- 7720
Destruct
Well I had tried that Mark but the problem was I wasn't getting an error, it was telling me it was initializing just fine although tables weren't appearing. I figured out problem was I missing the // on a line which should have been commented and that at least got me to the stage where I could view the SQL. I player around with the SQL and fgiured out that this line:
Code
was causing me problems. I changed it to:
Code
And it worked fine. What I do find confusing is that before making this change, the SQL statement was executing just fine in phpMyAdmin but it just wouldn't work on site. WOnder why that is.
Reallly dificult to tell without having your code in front of me. The text wrapping on these forums really doesn't make this kind of diagnostic easy.
Feel free to shoot be a copy of the code to markwest at PostNuke dot com as i'll take a further look.
-Mark
