PrestaShop SQL Manager

PrestaShop uses a database table prefix system (e.g., ps_) to identify the tables that belong to its installation. This prefix is defined during the initial configuration of PrestaShop and is user-customizable.

Why does PrestaShop use a prefix for tables?

The use of prefixing has several advantages, including:

  1. Security:
    Table prefixing helps improve security against SQL Injection attacks. An attacker attempting to exploit a vulnerability may not know the specific prefix used in your installation, making it more difficult to detect database tables.

  2. Multi-installation on the same database:
    If multiple PrestaShop sites share the same database, each installation can use a different prefix to avoid conflicts between tables.

  3. Customization and organization:
    Using the prefix allows administrators to easily distinguish PrestaShop tables from those of other applications or systems that share the same database.

How does the prefix work?

During installation, PrestaShop allows you to specify a custom prefix. By default, the prefix is ps_, but it can be changed (e.g. to shop_, mystore_, etc.).

Example:

  • A standard table with the default prefix might be ps_stock_available.
  • If you choose another prefix, such as mystore_, the table will be mystore_stock_available.

Adapting queries to prefix

owing to the fact that table prefixes can vary between installations, in SQL queries you must manually replace the placeholder [PREFIX] with the prefix actually used in your configuration.

Example of a custom prefix query

If the prefix is mystore_ and you want to check the quantity of a product, you need to change the query from:

[code=language-sql] SELECT quantity FROM [PREFIX]stock_available WHERE id_product = 123 AND id_product_attribute = 0[/code]

a:

[code=language-sql] SELECT quantity FROM mystore_stock_available WHERE id_product = 123 AND id_product_attribute = 0[/code]

How to verify the prefix used?

If you do not know the prefix used in your installation, you can easily check it:

  • By checking the configuration file:
    Open the app/config/parameters.php file of your PrestaShop installation. Look for the line: 'database_prefix' => 'ps_',

  • Looking directly into the database:
    Access the database through a tool such as phpMyAdmin and check the table names: all will start with the prefix used.

Safety tips

  • Use a custom, complex prefix during installation (e.g., myshop123_ instead of ps_) to increase security against targeted attacks.
  • Avoid using prefixes that are too simple or easily predictable.

In conclusion, the prefix is an essential element of table management in PrestaShop, and customizing it offers both security and flexibility benefits. Be sure to replace [PREFIX] in queries with your system's actual prefix!

Author: Loris Modena

Loris Modena

SENIOR DEVELOPER

Per Ind Loris Modena owner of Arte e Informatica, began working in the computer industry in 1989 as a systems engineer in charge of maintenance and installation of computer systems. He starts programming for the web in 1997 dealing with CGI programming in PERL and later moving to programming in PHP and JavaScript. During this period he approaches the Open source world and Linux server management.

Product added to wishlist