3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getListTableForeignKeysSQL($table, $database = null) { $sql = "SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, ". "k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ ". "FROM information_schema.key_column_usage k /*!50116 ". "INNER JOIN information_schema.referential_constraints c ON ". " c.constraint_name = k.constraint_name AND ". " c.table_name = '$table' */ WHERE k.table_name = '$table'"; $databaseNameSql = null === $database ? "'$database'" : 'DATABASE()'; $sql .= " AND k.table_schema = $databaseNameSql /*!50116 AND c.constraint_schema = $databaseNameSql */"; $sql .= " AND k.`REFERENCED_COLUMN_NAME` is not NULL"; return $sql; } echo getListTableForeignKeysSQL('AreaLayoutsUsingPresets'). "\n"; echo getListTableForeignKeysSQL('AreaLayoutsUsingPresets', 'concrete5db'). "\n";
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ FROM information_schema.key_column_usage k /*!50116 INNER JOIN information_schema.referential_constraints c ON c.constraint_name = k.constraint_name AND c.table_name = 'AreaLayoutsUsingPresets' */ WHERE k.table_name = 'AreaLayoutsUsingPresets' AND k.table_schema = '' /*!50116 AND c.constraint_schema = '' */ AND k.`REFERENCED_COLUMN_NAME` is not NULL SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ FROM information_schema.key_column_usage k /*!50116 INNER JOIN information_schema.referential_constraints c ON c.constraint_name = k.constraint_name AND c.table_name = 'AreaLayoutsUsingPresets' */ WHERE k.table_name = 'AreaLayoutsUsingPresets' AND k.table_schema = DATABASE() /*!50116 AND c.constraint_schema = DATABASE() */ AND k.`REFERENCED_COLUMN_NAME` is not NULL
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ FROM information_schema.key_column_usage k /*!50116 INNER JOIN information_schema.referential_constraints c ON c.constraint_name = k.constraint_name AND c.table_name = 'AreaLayoutsUsingPresets' */ WHERE k.table_name = 'AreaLayoutsUsingPresets' AND k.table_schema = '' /*!50116 AND c.constraint_schema = '' */ AND k.`REFERENCED_COLUMN_NAME` is not NULL SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ FROM information_schema.key_column_usage k /*!50116 INNER JOIN information_schema.referential_constraints c ON c.constraint_name = k.constraint_name AND c.table_name = 'AreaLayoutsUsingPresets' */ WHERE k.table_name = 'AreaLayoutsUsingPresets' AND k.table_schema = DATABASE() /*!50116 AND c.constraint_schema = DATABASE() */ AND k.`REFERENCED_COLUMN_NAME` is not NULL

preferences:
222.61 ms | 404 KiB | 254 Q