PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 571 All time: 5,366 This week: 284Up
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: 107168 in Germany Germany
Week rank: 45 Up3 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  
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

 Version Control Unique User Downloads Download Rankings  
 0%
Total:571
This week:0
All time:5,366
This week:284Up
User Comments (1)