| INFORMATION_SCHEMA | |
|---|---|
| $sql=" SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='$table' AND CONSTRAINT_NAME LIKE'FK%'"; | récupération des contraintes nommés FK... COLUMN_NAME//clé étrangère REFERENCED_TABLE_NAME//table correspondante REFERENCED_COLUMN_NAME//champ de la table correspondante |
| $sql = " SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='$table' AND EXTRA='auto_increment' AND COLUMN_KEY = 'PRI'"; | Champ primary key + auto increment |
| $sql = " SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$table'"; | Liste des champs |
| $sql=" SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '$db' "; | Liste des tables |
| Astuces | |
|---|---|
| select MAX(LENGTH(unChamp)) from table; | taille max contenu dans un champ (pour size input...) |
| $liste = implode(', ',$tab); | Séparer des champs par des virgules |
| foreach($tab as $val) $tabTailleMax[] = "MAX(LENGTH(".$val."))"; $sql = 'select '. implode(', ',$tabTailleMax).' from table'; $sth = $this->dbh->query($sql); $res = $sth->fetch(PDO::FETCH_NUM); foreach($res as $val) $tab = $val ; | Taille champs input automatique sur liste |
WHERE