PHP Classes

File: demo.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP MySQL User Management   demo.php   Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: Small demo to show capabilities
Class: PHP MySQL User Management
List, add, modify and remove MySQL server accounts
Author: By
Last change: Add file comment
Date: 9 years ago
Size: 1,024 bytes
 

Contents

Class file image Download
<?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";
}