A simple PHP script to validate MySQL database integrity by checking connections, database existence, table listings, and detecting duplicate entries in PRIMARY and UNIQUE indexes.
- Validates MySQL connection.
- Checks if the specified database exists.
- Reads and lists all tables in the database.
- Detects duplicate values in
PRIMARYandUNIQUEindexes. - Outputs results in structured JSON.
- PHP 7.4+ (with PDO and MySQL support)
- MySQL or MariaDB
- Clone the repository:
git clone https://github.com/BaseMax/php-database-integrity-checker.git
cd php-database-integrity-checker-
Place
checker.phpon your server. -
Access the script via POST request with required parameters.
host(optional, default:localhost)port(optional, default:3306)user(required)pass(optional)dbname(required)
Example POST request with curl:
curl -X POST -d "host=localhost&port=3306&user=root&pass=secret&dbname=testdb" \
http://yourserver.com/checker.php{
"status": true,
"database": "testdb",
"tables_checked": 5,
"issues": [
{
"table": "users",
"index": "PRIMARY",
"columns": ["id"],
"duplicates": [
{"id": 1, "cnt": 2},
{"id": 5, "cnt": 3}
]
}
]
}If no issues are found:
{
"status": true,
"database": "testdb",
"tables_checked": 5,
"issues": []
}If an error occurs (e.g., database not found):
{
"status": false,
"error": "Database 'testdb' does not exist."
}This project is licensed under the MIT License. See the LICENSE file for details.