-
Notifications
You must be signed in to change notification settings - Fork 1
/
Base.class.php
80 lines (42 loc) · 1.2 KB
/
Base.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
$DEFAULT_UNIQUE_ID = "00000";
require_once( "DBConfig.php" );
date_default_timezone_set( "Africa/Nairobi" );
try {
$dbh = new PDO( 'mysql:host=' . $DBHost . ';dbname=' . $DBName, $DBUser, $DBPass, array( PDO::ATTR_PERSISTENT => true ) );
$dbh -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e ) {
print "Error!: " . $e -> getMessage();
die();
}
function genRandomString( $length = 5, $seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) {
$returnValue = '';
for( $i = 0; $i < $length; $i++ ) {
$returnValue .= $seed[ rand( 0, strlen( $seed ) - 1 ) ];
}
return $returnValue;
}
Class Base {
private $uniqueID;
function setUniqueID( $uniqueID ) {
$this -> uniqueID = $uniqueID;
}
function getUniqueID() {
return $this -> uniqueID;
}
function genUniqueID( $length = 5, $seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) {
$returnValue = '00000';
$returnValue = genRandomString( $length, $seed );
$this -> setUniqueID( $returnValue );
}
function __construct( $uniqueID = "00000", $length = 5 ) {
if( $uniqueID == "00000" ) {
$this -> genUniqueID( $length );
}
else {
$this -> setUniqueID( $uniqueID );
}
}
}
?>