2015-05-29 19:27:45 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2015-07-05 00:03:15 +00:00
|
|
|
* Database wrapper container
|
2015-05-29 19:27:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Sakura;
|
|
|
|
|
|
|
|
class Database {
|
|
|
|
|
|
|
|
// Database container
|
2015-06-29 00:36:37 +00:00
|
|
|
private static $_DATABASE;
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
// Initialisation function
|
2015-07-05 00:03:15 +00:00
|
|
|
public static function init($wrapper) {
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-07-05 00:03:15 +00:00
|
|
|
// Make the wrapper class name lowercase
|
|
|
|
$wrapper = __NAMESPACE__ .'\DBWrapper\\'. strtolower($wrapper);
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
// Check if the class exists
|
2015-07-05 00:03:15 +00:00
|
|
|
if(!class_exists($wrapper))
|
|
|
|
trigger_error('Failed to load database wrapper', E_USER_ERROR);
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-07-05 00:03:15 +00:00
|
|
|
// Initialise SQL wrapper
|
|
|
|
self::$_DATABASE = new $wrapper;
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch from database
|
|
|
|
public static function fetch($table, $fetchAll = true, $data = null, $order = null, $limit = null, $group = null, $distinct = false, $column = '*', $prefix = null) {
|
|
|
|
|
|
|
|
return self::$_DATABASE->fetch($table, $fetchAll, $data, $order, $limit, $group, $distinct, $column, $prefix);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert into database
|
|
|
|
public static function insert($table, $data, $prefix = null) {
|
|
|
|
|
|
|
|
return self::$_DATABASE->insert($table, $data, $prefix);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update in database
|
|
|
|
public static function update($table, $data, $prefix = null) {
|
|
|
|
|
|
|
|
return self::$_DATABASE->update($table, $data, $prefix);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete from database
|
|
|
|
public static function delete($table, $data, $prefix = null) {
|
|
|
|
|
|
|
|
return self::$_DATABASE->delete($table, $data, $prefix);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-05 00:03:15 +00:00
|
|
|
// Count from database
|
|
|
|
public static function count($table, $data, $prefix = null) {
|
|
|
|
|
|
|
|
return self::$_DATABASE->count($table, $data, $prefix);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-29 19:27:45 +00:00
|
|
|
}
|