Check the integrity of database references
I recently had to write a little script to check the integrity of references inside a database.
Note: This was done as part of my work at Tribal Nova. Thanks for letting me share!
The script (command line only) is very simple and aims to check integrity of references (foreign keys or soft references). It’s for MySQL only and requires PHP5 with PDO. Foreign keys are automatically discovered and you can specify additional references in a mapping.xml file.
A report will be displayed. Upon this, you can choose to execute an action to resolve issues. You can:
- update values using a mapping.xml file which maps old values with new ones
- delete broken references
- follow the on update or on delete behaviour
To run it simply call it from the command line with connection info:
php integrity.php --database=my_db --username=root --password=root.
You can get some help using
php integrity.php --help
You can download it by clicking here.
comments powered by Disqus