PHP code example of clubdrei / db-user-manager
1. Go to this page and download the library: Download clubdrei/db-user-manager library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
clubdrei / db-user-manager example snippets
$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();