Documentation Menu

1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 7 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow Manual arrow 11. API Reference arrow [REVIEW] database->query

[REVIEW] database->query PDF Print E-mail

Last reviewed: Not reviewed
phpDocumentor

database->query

Executes the current SQL query string.

The syntax and semantics of SQL statements are beyond the scope of this manual.  Prior to Joomla 1.1 the only database software supported was MySQL and the reference manual may be found at http://dev.mysql.com/doc/. From Joomla 1.1 onwards support for multiple databases is provided using the ADODB database abstraction library.

Syntax

object query ( [array $params] )

$params
Array of parameters. This parameter is optional in Joomla 1.1 onwards and if omitted will default to an empty array. Introduced in Joomla 1.1 (ignored by prior versions).

This function returns a database resource object if successful or false if not.  The error code can be examined by calling database->getErrorNum and the error message can be obtained by calling database->getErrorMsg.

Examples

Example:

function countCategories() {
  global $database;
 
  $sql = "SELECT * FROM #__categories";
  $database->setQuery( $sql );
  if (!$result = $database->query()) {
    echo $database->stderr();
    return false;
  }
 
  return $database->getNumRows( $result );
 
}
 
echo 'There are ' . countCategories() . ' categories';

might produce:

There are 6 categories

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Monday, 25 December 2006 )
 
< Prev   Next >