| 2.5. Database Access |
| Prev | Chapter 2. Basics | Next |
|---|
VM uses its own database access class for dealing with the database.
The database class file is
/administrator/components/com_virtuemart/classes/ps_database.php.
This database class uses Joomla's global database object and provides additional functions, to be able to use older phpShop code. So this class is just a wrapper class for Joomla's database object and doesn't open new connections to the database!
Start a query: call the method query( string
$query )
$db->query( 'SELECT `id`, `email` FROM `#__users`');
Get the resulting record set: call method
next_record( void ):
$db->next_record();(returns false when no result can be returned or the end of the record set has been reached)
Fetch the value of an attribute of the record set: method
f( string $nameOfTheAttribute )
$db->f( 'email' );
Alternative: method sf( string $nameOfTheAttribute
) returns the value of the attribute specified by
$nameOfTheAttribute or - when it's not available - the value of
$vars[$nameOfTheAttribute].
Print (echo) the value of an attribute of the record set:
method p( string $nameOfTheAttribute )
$db->p( 'email' );
Alternative: method sp( string $nameOfTheAttribute
) prints the value of the attribute specified by
$nameOfTheAttribute or - when it's not available - the value of
$vars[$nameOfTheAttribute].
Get the number of returned records: method
num_rows( void ).
if( $db->num_rows() > 0 ) { // we have a record set! }