SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 65 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"

We do this using the setQuery() method; this does not perform
the query.
$db =& JFactory::getDBO();
$result = $db->setQuery($query);
Once we have set the query we want to perform, we use the query() method to
execute the query. This is similar to using the PHP function mysql_query(). If the
query is successful and is a SELECT, SHOW, DESCRIBE, or EXPLAIN query, a resource
will be returned. If the query is successful, and is not one of the above query types,
true will be returned. If the query fails, false will be returned.
$db =& JFactory::getDBO();
if (!$result = $db->setQuery($query))
{
// handle failed query
// use $table->getError() for more information
}
Writing Queries
There are some rules we need to be aware of when we build database queries.
Use the #__ symbolic prefix at the start of all table names.
Use the nameQuote() method to encapsulate named query elements.
Use the Quote() method to encapsulate values.
??? ??? ???
Chapter 3
[ 47 ]
The symbolic prefix guarantees that we use the correct prefix for the current
Joomla! installation; an alternative symbolic prefix to #__ can be used if necessary.


Pages:
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77