Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules

Search

Donate to XOOPS!

Please select an amount to donate


Do you want your username revealed with your donation?
Yes - List me as a Generous Donor
No - List my donation as from an Anonymous Donor


Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

admin Arabic banner block Christmas comments cumulus DayDawn dhsoft e-Commerce E-Learning Git Google GUI hacks instant-zero jQuery module mygalleries news Nordic Olédrion oxygen PageRank PHP rmcommon security SEO simple-XOOPS Smarty sport tag Theme tutorial wiki WOX xoops XoopsEngine ZendFramework

New Users

Registering user

# 133946

HamptonUdolf

Welcome to XOOPS!
[Main Page]

Dev:using the databse

From XOOPS Web Application System

Main Page | Recent changes | Edit this page | Page history | Switch to MediaWiki mode

Printable version | Disclaimers | Privacy policy
Category: Development

We'll assume that you have setup the module handler as shown in XoopsObjectHandler. There are a number of useful functions available. There is also this Kickstart page on XoopsDB.

Querying Data

Generally, you will query the database to get a result and then operate on the returned data:

   $sql = 'SELECT * FROM'.$this->db->prefix('table').'WHERE ... ORDER BY...';
   $result =& $this->db->query($sql);
   while ($array = $this->db->fetchArray($result)) {
       //do something useful here
   }


Useful Functions

   * prefix($tablename) - adds XOOPS_DB_PREFIX and _ to $tablename
   * &query($sql,$limit,$start) - returns a reference to the query results using the SQL statement $sql, limited to $limit rows, starting at row $start. This result may be read using functions such as fetchRow and fetchArray. This function is actually an alias for &queryF.
   * fetchArray($result) - returns associative array (name => value) from $result and removes the row from $result.
   * fetchRow($result) - returns enumerated array (X => value, where X starts at 0 and increments for each field) from $result and removes the row from $result.

If you do a query as "SELECT * FROM...", you may need to loop through the results and thus you may need these functions:

   * getRowsNum($result) - returns number of rows in $result
   * getFieldsNum($result) - returns number of fields in $result
   * getFieldName($result,$offset) - returns name of field based on $offset from first field in $result
   * getFieldType($result,$offset) - returns type of field based on $offset from first field in $result


Data Preparation for Database Insertion

These functions may be useful, too:

   * quoteString($str) - Returns escaped string text with single quotes around it to be safely stored in database

back to Main Page

Retrieved from "http://xoops.org/modules/mediawiki/index.php/Dev:using_the_databse"

This page has been accessed 2,176 times. This page was last modified 02:09, 16 December 2007. Content is available under XOOPS Web Application System.