How to view the MySQL query sent by an admin form?

The Bootstrap Admin Forms are built with PHP Form Builder. They are located in the admin/inc/forms/ folder.

How to view the MySQL query sent by an admin form?

PHP Form Builder is included in PHP CRUD Generator's package.
With all its functionnalities and plugins.

The MySQL queries sent to your database are built with PHP Form Builder's MySQL wrapper class.

Documentation and sample codes are available here on PHP Form Builder's website.

PHP Form Builder
PHP Form Builder

All the Admin forms are located in the same folder in admin/inc/forms/.

Each table uses 3 forms:

  • table-create.php
  • table-edit.php
  • table-delete.php

where "table" is the sanitized name of your table.

All the actions (database recordings) are done in the same files after validation.

There's 2 different cases

If your query fails (Case n°1)

(you see the ugly alert message Error while recording after posting the form)

  • In development mode (on localhost), you should already see the error details with the SQL query

  • In production mode (on production server)

    Find the following block in your form file:

    if (ENVIRONMENT == 'development') {
    $msg_content .= '<br>' . $e->getMessage() . '<br>' . $db->getLastSql();
    and replace == with !== Then post your form again and the SQL query will be shown.

Once you've posted your query, copy/paste it directly into your database manager (PhpMyAdmin or similar).
You'll see in return if a field has an invalid value, or if there's some other problem in the query.

If the query works in your database manager but not in PHPCG, there can be 2 causes:

  1. The MySQL user with which you connect from PHPCG has insufficient privileges to perform the query (check your MySQL users' privileges)
  2. The table on which the query does not meet the prerequisites. particulary, each table must have an auto-incremented primary key. If it doesn't, the records are still inserted / edited from the admin dashboard, but the program returns the Error while recording.
    You can check from the generator, in the Build Create / Update Forms part. If your table does have an auto-incremented primary key, you should see PRIMARY and AUTO-INCREMENT badges under the field name.

If your query is successful - (Case n°2)

To show the MySQL query sent by a form you just have to add the following code to the form
just after the code where the query is sent:

echo $db->getLastSql();


To edit the Bootstrap Admin Forms you must beforehand:

PHP CRUD tutorial main page