PHPackages                             zortje/mysql-keeper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. zortje/mysql-keeper

ActiveLibrary[Database &amp; ORM](/categories/database)

zortje/mysql-keeper
===================

Find incorrect configurations or missed optimization opportunities in MySQL databases

0.4.0(11y ago)6161[5 issues](https://github.com/zortje/mysql-keeper/issues)[1 PRs](https://github.com/zortje/mysql-keeper/pulls)MITPHPPHP &gt;=5.4

Since Jan 17Pushed 9y ago3 watchersCompare

[ Source](https://github.com/zortje/mysql-keeper)[ Packagist](https://packagist.org/packages/zortje/mysql-keeper)[ RSS](/packages/zortje-mysql-keeper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

MySQL Keeper
============

[](#mysql-keeper)

Find incorrect configurations or missed optimization opportunities in MySQL databases.

[![Packagist](https://camo.githubusercontent.com/77952b963e906fd77ae5ea7a1a443a23517449daebc4f4c910a8669418d6569d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6f72746a652f6d7973716c2d6b65657065722e7376673f7374796c653d666c6174)](https://packagist.org/packages/zortje/mysql-keeper)[![Travis branch](https://camo.githubusercontent.com/9cb633d2c0673ce0962be666dab2c7306229d28e7dbbe242679771780ee53428/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7a6f72746a652f6d7973716c2d6b65657065722f6d61737465722e737667)](https://travis-ci.org/zortje/mysql-keeper)[![Scrutinizer branch](https://camo.githubusercontent.com/5547574d01bfdb8d07312dcec7bf471a91e1dd894361b3b1fffeb37f24d9704a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7a6f72746a652f6d7973716c2d6b65657065722f6d61737465722e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/zortje/mysql-keeper/?branch=master)[![Scrutinizer](https://camo.githubusercontent.com/d1048354c1ceedfa20128a929172199141fed02563932434ceae5c3794899279/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a6f72746a652f6d7973716c2d6b65657065722e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/zortje/mysql-keeper/?branch=master)[![Dependency Status](https://camo.githubusercontent.com/565de5d4003bec4b8a6ff892e65a2ee42fdfd85bbf92de04131c2ebd12e18848/68747470733a2f2f646570656e64656e637963692e636f6d2f6769746875622f7a6f72746a652f6d7973716c2d6b65657065722f6261646765)](https://dependencyci.com/github/zortje/mysql-keeper)[![Packagist](https://camo.githubusercontent.com/ad8c3f466c9da6104cb1b7d26327374db5dde3c14485cacca1b961cfbe29060f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6f72746a652f6d7973716c2d6b65657065722e7376673f7374796c653d666c6174)](https://packagist.org/packages/zortje/mysql-keeper)

[![SensioLabsInsight](https://camo.githubusercontent.com/3992db59ac6026ed28a30fb5e1deea581af4b695749b2c1957dc9d0a13d5aeb6/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f35653832353132632d363534392d343231392d613461642d3064363737316262343863392f6269672e706e67)](https://insight.sensiolabs.com/projects/5e82512c-6549-4219-a4ad-0d6771bb48c9)

Features
--------

[](#features)

Detects the following issues

- Duplicate indices
- Missing primary key on auto\_increment column
- Redundant unique index on primary key
- Redundant key index on primary key
- Inconsistent usage of collation between table and columns

Installing via Composer
-----------------------

[](#installing-via-composer)

The recommended way to install MySQL Keeper is though [Composer](https://getcomposer.org/).

```
{
    "require": {
        "zortje/mysql-keeper": "~0.0"
    }
}
```

Usage
-----

[](#usage)

```
$pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp', 'root', '');

$database = DatabaseFactory::create($pdo);
$databaseResult = $database->getResult();
```

The `$databaseResult` array will look something like this with the first level keys being table names.

```
[
	'users' => [
		'issues' => [
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Set as auto_increment but has no primary key'
			],
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Set as auto_increment but is not set as primary'
			]
		],
		'optimizations' => [
			[
				'type' => 'field',
				'field' => 'id',
				'description' => 'Field should be unsigned, as no field values are negative'
			]
		]
	]
];
```

Usage with Melody
-----------------

[](#usage-with-melody)

[Melody](http://melody.sensiolabs.org) allows inline Composer requirements to simply execute PHP scripts.

mysql-keeper\_myapp.php

```
