Creating or Modifying a table

Modifying the database schema

Creating a New Table

Creating a new table is done with the SQL CREATE TABLE command. You may provide a .sql file that does this operation with instructions to run the file in Admin > Tools > Install SQL Patches, or you may embed the CREATE TABLE operation in a file that is run automatically in the admin (for example, admin/includes/functions/extra_functions/your-feature.php).

When you create a new table, be sure to create a defined constant for the table name on both the storefront and admin side. Example:

<?php
define('TABLE_PRODUCTS_XSELL', DB_PREFIX . 'products_xsell');

This would go in includes/extra_datafiles/xsell_definitions.php and admin/includes/extra_datafiles/xsell_definitions.php.

Modifying a Table

Changing a table’s structure - adding or removing fields, modifying default values and so forth - is done with the SQL ALTER TABLE command. Again, you may provide a .sql file or automate this action.




Still have questions? Use the Search box in the upper right, or try the full list of FAQs. If you can't find it there, head over to the Zen Cart support forum and ask there in the appropriate subforum. In your post, please include your Zen Cart and PHP versions, and a link to your site.

Is there an error or omission on this page? Please post to General Questions on the support forum. Or, if you'd like to open a pull request, just review the guidelines and get started. You can even PR right here.
Last modified November 29, 2021 by Scott C Wilson (4d7f1004).