I'm using the following in my getall() function of the pnuserapi:
function Itinerary_userapi_getall
($args){ // Get arguments from argument array - all arguments to this function // should be obtained from the $args array, getting them from other // places such as the environment is not allowed, as that makes // assumptions that will not hold in future versions of PostNuke extract($args);
// Optional arguments. if (!
isset($see)) { $see =
'events';
} $items =
array();
// Security check - important to do this as early on as possible to // avoid potential security holes or just too much wasted processing if (!pnSecAuthAction
(0,
'Itinerary::',
'::', ACCESS_OVERVIEW
)) { return $items;
} // 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 $dbconn =& pnDBGetConn
(true);
$pntable =& pnDBGetTables
();
$sql =
'';
// 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 $Itineraryetable =
$pntable['itinerary_events'];
$Itineraryecolumn = &
$pntable['itin_events_column'];
$Itineraryitable =
$pntable['itinerary_items'];
$Itineraryicolumn = &
$pntable['itin_items_column'];
$Itineraryttable =
$pntable['itinerary_types'];
$Itinerarytcolumn = &
$pntable['itin_types_column'];
$Itineraryctable =
$pntable['itinerary_config'];
$Itineraryccolumn = &
$pntable['itin_config_column'];
$Itineraryatable =
$pntable['itinerary_address'];
$Itineraryacolumn = &
$pntable['itin_address_column'];
$Itineraryutable =
$pntable['itinerary_users'];
$Itineraryucolumn = &
$pntable['itin_users_column'];
// Get items - 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 SelectLimit() command allows for simpler debug // operation if it is ever needed $sql =
"SELECT $Itineraryecolumn[eid],
$Itineraryecolumn[ename],
$Itineraryecolumn[edesc],
$Itineraryecolumn[estart],
$Itineraryecolumn[eend]
FROM $Itineraryetable
ORDER BY $Itineraryecolumn[estart]";
echo $sql;
$result =&
$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', _GETFAILED
);
return false;
} // Put items into result array. Note that each item is checked // individually to ensure that the user is allowed access to it before it // is added to the results array for (; !
$result->
EOF;
$result->
MoveNext()) { list($eid,
$ename,
$edesc,
$estart,
$eend) =
$result->
fields;
if (pnSecAuthAction
(0,
'Itinerary::',
"$ename::$eid", ACCESS_OVERVIEW
)) { $items[] =
array('eid' =>
$eid,
'ename' =>
$ename,
'edesc' =>
$edesc,
'estart' =>
$estart,
'eend' =>
$eend);
} } // All successful database queries produce a result set, and that result // set should be closed when it has been finished with $result->
Close();
// Return the items return $items;
}
On executing, I get this error (notice that the value for $
SQL is echoed before its execution so I can see the formed
SQL statement):
SELECT itin_eventid, itin_eventname, itin_eventdesc, itin_eventstart, itin_eventend FROM pn_itinerary_events ORDER BY itin_eventstart
Fatal error:
mysql error:
[1064: 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
' , FROM' at line
1] in EXECUTE
("SELECT , , FROM ") in f:\ncm\www\fsintra\includes\classes\adodb\adodb-errorhandler.inc.php on line
153
So, why would the $
SQL now be stripped of everything but "SELECT , , FROM"??
An interestng item... I put this in place of $
SQL in the
$result =& $dbconn->Execute($SQL);:
$result =& $dbconn->Execute('SELECT itin_eventid, itin_eventname, itin_eventdesc, itin_eventstart, itin_eventend FROM pn_itinerary_events ORDER BY itin_eventstart');
This also returns the same error, BUT if I break the
SQL (bad table name for example) like so:
$result =& $dbconn->Execute('SELECT itin_eventid, itin_eventname, itin_eventdesc, itin_eventstart, itin_eventend FROM pn_itinerary_events ORDER BY itin_BADTABLENAME');
Then, it returns the
SQL in the error code like:
Fatal error:
mysql error:
[1054: Unknown column
'itin_BADTABLENAME' in
'order clause'] in EXECUTE
("SELECT itin_eventid, itin_eventname, itin_eventdesc, itin_eventstart, itin_eventend FROM pn_itinerary_events ORDER BY itin_BADTABLENAME") in f:\ncm\www\fsintra\includes\classes\adodb\adodb-errorhandler.inc.php on line
153
So why, with the correctly formed
SQL does the query revert to "SELECT , , FROM" ???
Anyone seen this before? Should I use a different method? I'm just following the example module
DB calls.
Thanks,
Nolan M.
UHEweb