User Login    
 + Register
  • Main navigation
Login
Username:

Password:

Remember me



Lost Password?

Register now!
Who's Online
82 user(s) are online (11 user(s) are browsing XoopsWiki)

Members: 3
Guests: 79

pacho, bakergd, Runeher, more...
[Main Page]

Dev:using the databse

From XOOPS Project

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://www.xoops.org/modules/mediawiki/index.php/Dev:using_the_databse"

This page has been accessed 599 times. This page was last modified 02:09, 16 December 2007. Content is available under XOOPS Project.


Developers for Hire
Developers for Hire
Local Support Sites
Make a donation
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


Powered by
XOOPS Code hosted on SourceForge

Powered by PHP

PHP 5

Powered by MySQL

Powered by Smarty

OSI certified

GPL

All content on this site is subject to the Creative Commons License
Top Tags
Theme (5) news (2) security (2) sport (1) Arabic (1) wiki (1) Christmas (1) jQuery (1) tag (1) module (1) SEO (1) comments (1)
Advertisement