Databases


This book isn't about database programming, but if you are familiar with that concept, I want you to know how PHP-Nuke makes databases accessible. If these terms and concepts are meaningless to you, just skip ahead to the next topic.

To query one or more rows from the PHP-Nuke database, use something like this:


$result = $db->sql_query("SELECT field1, field2 FROM table")

The variable, $result, contains the queried rows. To get them out, use something like this:

 While list($field1, $field2) = $db->sql_fetchrow($result) {   /* code here */ } 

$field1 contains the first column's data; $field2 contains the second column's data. This construct repeats once for each row of data that $result contains. You can see how many rows that is by executing this:

 $numrows = $db->sql_numrows($result) 

The $db object variable is defined by PHP-Nuke and is available in all modules. You will, however, need to explicitly declare it within each function of a module:

 Global $db 

Sidebar . FAQ

Do I have to have an index.php for each module folder?

Yes. If you don't, PHP-Nuke won't do anything when you try to access that module.

Where can I find out more about creating modules for PHP-Nuke?

www.phpnuke.org is the best place to start. The online "PHP-Nuke HOWTO" document, available at that Web site, contains more details on how to create custom blocks and modules. Searching the Web (using a search engine like Google) can also turn up some helpful hints.

I do recommend becoming more familiar with your database server (typically MySQL), since a lot of what you need to know to make custom modules is really the MySQL query language and MySQL administrative tasks. The site www.mysql.org contains information and documentation on MySQL, and there are a number of excellent books on the market that cover MySQL.




    PHP-Nuke Garage
    PHP-Nuke Garage
    ISBN: 0131855166
    EAN: 2147483647
    Year: 2006
    Pages: 235
    Authors: Don Jones

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net