A client wants to search a table within the Joomla database . Create a SELECT query to search this table based on user-defined criteria and present the list of results with navigational aids. - Your organization uses an external accounting system running on an SQL database. Stakeholders want to be able to view a summary of expenses at any time. Create a SELECT query using SUM and GROUP BY to provide a report via the website.
- A local professional group would like people to complete a survey consisting of select and text boxes. The database is located on a remote machine. Some fields are required but others are not. Additionally, information such as the user’s IP address and, if registered, username and name should be recorded. Create a database connection to the remote database and an INSERT query that will use several DBQ variables to prompt for the user’s input. Write snippets of PHP code to extract the IP and user name so that this information can be recorded as well. - A company wants an application where a manager selects a list of clients, then clicks on a client’s name to view, edit, or delete the client’s record. Create the required queries and use DBQ Professional to create links between the queries. 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 |