<?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";
}
|