LearnWebDesignOnline.com is proudly hosted by Hostmonster.com

If you are writing custom functionality into Zencart, there may be times when you need to query the database. For the purpose of this example, let's say that you want to retrieve the value of the admin email as listed in the admin control panel at "Admin -> Configuration -> Email Options -> Email Address (Displayed to Contact You)".
First you have to figure out the SQL statement that would retrieve that value from the database. You can use phpMyAdmin or other tools to browse the database until you find the place where the data is kept.
The PHP code to query the database for this value would be ...
<?php
$contactEmail = '';
$sql = "select configuration_value from " . TABLE_CONFIGURATION. " where configuration_key = 'STORE_OWNER_EMAIL_ADDRESS' limit 1";
$contact_emails = $db->Execute($sql);
$contactEmail = $contact_emails->fields['configuration_value'];
?>
Note how we use the database table constant TABLE_CONFIGURATION. This is because some admins may have installed the database with table prefix and the table name may be different with different installs. The database table constant takes care of adding in the right database prefix.
Also note the $db object that is available to you to use.