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.
[edit]
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
}
[edit]
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
[edit]
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











![[Main Page]](/modules/mediawiki/images/mediawiki.png)


