Why is it important to restrict DDL commands like CREATE, ALTER, and DROP when using transactions in PHP database operations?

It is important to restrict DDL commands like CREATE, ALTER, and DROP when using transactions in PHP database operations to prevent accidental or malicious changes to the database structure that could lead to data loss or corruption. By limiting the types of commands that can be executed within a transaction, you can ensure the integrity of your database and avoid unexpected issues.

// Restrict DDL commands within a transaction
$pdo->exec("SET SESSION sql_require_primary_key=1"); // Prevent altering tables without primary keys
$pdo->exec("SET SESSION sql_safe_updates=1"); // Prevent deleting all rows in a table without a WHERE clause