Skip to content

BaseMax/php-database-integrity-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

PHP Database Integrity Checker

License: MIT

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.


Features

  • Validates MySQL connection.
  • Checks if the specified database exists.
  • Reads and lists all tables in the database.
  • Detects duplicate values in PRIMARY and UNIQUE indexes.
  • Outputs results in structured JSON.

Requirements

  • PHP 7.4+ (with PDO and MySQL support)
  • MySQL or MariaDB

Installation

  1. Clone the repository:
git clone http://github.com/BaseMax/php-database-integrity-checker.git
cd php-database-integrity-checker
  1. Place checker.php on your server.

  2. Access the script via POST request with required parameters.


Usage

Required POST 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

Sample JSON Output:

{
    "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."
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A PHP script to validate MySQL database integrity and detect duplicate entries in PRIMARY and UNIQUE indexes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages