PHP Classes

PHP MySQL User Management: List, add, modify and remove MySQL server accounts

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 69%Total: 573 This week: 1All time: 5,358 This week: 41Up
Version License PHP version Categories
myusers 1.0.0BSD License5.3PHP 5, Databases, User Management, Sy...
Description 

Author

This package can list, add, modify and remove MySQL server user accounts.

It can connect to the main accounts mysql database of a given MySQL server using PDO with the root account to perform operations with the MySQL server users.

There is one class that abstracts all the attributes and options of each MySQL user permission, like user name, password, privileges, etc..

The main class can perform all sorts of operations with database user records like:

- Load user permissions for a given database and host
- Check if a given user records exist
- Get the hash of a given password
- Create new user records
- Grant or revoke privileges of a given user
- Get user privileges for all databases he has access
- Delete a given user
- Make server reload the latest user privileges

Innovation Award
PHP Programming Innovation award nominee
November 2014
Number 11
Before an application can access a MySQL database, there must exist at least one user record in a special MySQL database that defines the user name, password, the databases and tables the user can access and the types queries that can be execute on those tables.

This class can perform the necessary operations to manipulate MySQL server user records with the permissions the users need to access the databases on the current server.

Manuel Lemos
Picture of Maik Greubel
  Performance   Level  
Name: Maik Greubel <contact>
Classes: 10 packages by
Country: Germany Germany
Age: ???
All time rank: 105967 in Germany Germany
Week rank: 47 Up2 in Germany Germany Up
Innovation award
Innovation award
Nominee: 4x

Recommendations

Manage MySQL user accounts
I need to create and delete MySQL users

Example

<?php
/**
 * This file is a example script to show the capabilities of MyUsers class.
 *
 * @package MyUsers
 * @author Maik Greubel <greubel@nkey.de>
 */
require 'MyUsers.php';

use
MyUsers\MyUsers;
use
MyUsers\User;
use \
Exception;

try
{
 
$myUsers = new MyUsers('root', '', 'localhost');
 
 
$newUser = new User();
 
$newUser->setUser('maik');
 
$newUser->setPassword('maik');
 
$newUser->setDatabase('test');
 
$newUser->setAllPrivileges(true);
 
$newUser->setGrantPrivilege(false);
 
$newUser->setHost('localhost');
 
 
$myUsers->persist($newUser);
 
 
$maik = $myUsers->loadUser('maik', 'test', 'localhost');
 
 
var_dump($maik);
 
 
$maik->setDatabase(null); // Full delete the user
 
$myUsers->delete($maik);
}
catch (
Exception $ex)
{
  if(
$ex->getPrevious() instanceof Exception)
  {
    echo
$ex->getPrevious()->getMessage() . "\n";
    echo
$ex->getPrevious()->getTraceAsString(). "\n";
  }
  echo
$ex->getMessage() . "\n";
  echo
$ex->getTraceAsString(). "\n";
}


  Files folder image Files (5)  
File Role Description
Plain text file MyUsers.php Class The main class
Plain text file User.php Class OR Mapping class needed by MyUsers
Accessible without login Plain text file composer.json Data To create class documentation
Accessible without login Plain text file demo.php Example Small demo to show capabilities
Accessible without login Plain text file phpdoc.dist.xml Data PHPDocumentor configuration

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:573
This week:1
All time:5,358
This week:41Up
User Ratings User Comments (1)
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:-
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:69%StarStarStarStar
Rank:347