Blog: Sniff, Sniff ... What's In Your Database?
Feb102014
One of the more under-utilized features of Zen Cart is the sniffer class, instantiated in both the admin- and store-side as $sniffer
during the auto_load start-up. This class allows you to interrogate the database to determine if
- A table already exists, via function
table_exists
. - A field in a table already exists, via function
field_exists
. - A field in a table already exists and is of a specific type, via function
field_type
.
If you're developing a plugin that makes database-related changes, this class can help you determine, for instance, whether the plugin's new field updated_by
is already present in the orders_status_history
(TABLE_ORDERS_STATUS_HISTORY
) table:
if (!$sniffer->field_exists(TABLE_ORDERS_STATUS_HISTORY, 'updated_by') { {insert the updated_by field} }
Using Zen Cart's built-in class also insulates your plugin from any database API changes in the future!
Information
Latest Blog [View All]
External Links
Say "Thanks"
If I've helped you on the Zen Cart forums or you've found one of my free plugins helpful, feel free to give a little back by clicking here.
Copyright © 2012-2021 Vinos de Frutas Tropicales. Powered by Zen Cart