Create Mysql users and manage privileges easily.
This project makes easier the MySQL User Account Management in PHP and it avoids the use of raw SQL queries.
$ composer require shinbuntu/db-user
$dbUserManager = new DbUser($dbConnection);
$dbUserManager->createUser('test_username', '!super_secure_password$');
$dbUserManager->dropUser('test_username');
$dbUserManager->userExist('test_username');
$dbUserManager->grantPrivileges(
'test_username',
[
DbUser::PRIVILEGE_CREATE_USER,
DbUser::PRIVILEGE_CREATE,
DbUser::PRIVILEGE_GRANT_OPTION,
DbUser::PRIVILEGE_ALTER,
DbUser::PRIVILEGE_FILE,
DbUser::PRIVILEGE_RELOAD,
DbUser::PRIVILEGE_SELECT,
DbUser::PRIVILEGE_INSERT,
DbUser::PRIVILEGE_UPDATE,
DbUser::PRIVILEGE_DELETE,
]
);
$dbUserManager->grantPrivileges(
'test_username',
[
DbUser::PRIVILEGE_SELECT,
DbUser::PRIVILEGE_INSERT,
DbUser::PRIVILEGE_UPDATE,
DbUser::PRIVILEGE_DELETE,
],
'test_database_name'
);
$dbUserManager->grantPrivileges(
'test_username',
[
DbUser::PRIVILEGE_SELECT,
DbUser::PRIVILEGE_INSERT,
DbUser::PRIVILEGE_UPDATE,
DbUser::PRIVILEGE_DELETE,
],
'test_database_name',
'test_table_name'
);
$dbUserManager->revokePrivileges(
'test_username',
[
DbUser::PRIVILEGE_CREATE_USER,
DbUser::PRIVILEGE_CREATE,
DbUser::PRIVILEGE_GRANT_OPTION,
DbUser::PRIVILEGE_ALTER,
DbUser::PRIVILEGE_FILE,
DbUser::PRIVILEGE_RELOAD,
DbUser::PRIVILEGE_SELECT,
DbUser::PRIVILEGE_INSERT,
DbUser::PRIVILEGE_UPDATE,
DbUser::PRIVILEGE_DELETE,
]
);
$dbUserManager->revokePrivileges(
'test_username',
[
DbUser::PRIVILEGE_SELECT,
DbUser::PRIVILEGE_INSERT,
DbUser::PRIVILEGE_UPDATE,
DbUser::PRIVILEGE_DELETE,
],
'test_database_name'
);
$dbUserManager->revokePrivileges(
'test_username',
[
DbUser::PRIVILEGE_SELECT,
DbUser::PRIVILEGE_INSERT,
DbUser::PRIVILEGE_UPDATE,
DbUser::PRIVILEGE_DELETE,
],
'test_database_name',
'test_table_name'
);
$dbUserManager->flushPrivileges();
See the CONTRIBUTING file.
The project is open-sourced software licensed under the MIT license.