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
|
|
|
*/
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-05-29 19:27:45 +00:00
|
|
|
namespace Sakura;
|
|
|
|
|
2015-10-18 19:06:30 +00:00
|
|
|
/**
|
|
|
|
* Class Database
|
|
|
|
* @package Sakura
|
|
|
|
*/
|
2015-09-14 20:51:23 +00:00
|
|
|
class Database
|
|
|
|
{
|
2015-05-29 19:27:45 +00:00
|
|
|
// Database container
|
2015-09-14 20:51:23 +00:00
|
|
|
public static $database;
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
// Initialisation function
|
2015-09-14 20:51:23 +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
|
2015-09-14 20:51:23 +00:00
|
|
|
$wrapper = __NAMESPACE__ . '\DBWrapper\\' . strtolower($wrapper);
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
// Check if the class exists
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!class_exists($wrapper)) {
|
2015-07-05 00:03:15 +00:00
|
|
|
trigger_error('Failed to load database wrapper', E_USER_ERROR);
|
2015-09-06 01:04:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-05 00:03:15 +00:00
|
|
|
// Initialise SQL wrapper
|
2015-09-14 20:51:23 +00:00
|
|
|
self::$database = new $wrapper;
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-21 22:07:45 +00:00
|
|
|
// Select from database
|
2015-09-14 20:51:23 +00:00
|
|
|
public static function select($table, $data = null, $order = null, $limit = null, $group = null, $distinct = false, $column = '*', $prefix = null)
|
|
|
|
{
|
2015-08-21 22:07:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
return self::$database->select($table, $data, $order, $limit, $group, $distinct, $column, $prefix);
|
2015-08-21 22:07:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-29 19:27:45 +00:00
|
|
|
// Fetch from database
|
2015-09-14 20:51:23 +00:00
|
|
|
public static function fetch($table, $fetchAll = true, $data = null, $order = null, $limit = null, $group = null, $distinct = false, $column = '*', $prefix = null)
|
|
|
|
{
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
return self::$database->fetch($table, $fetchAll, $data, $order, $limit, $group, $distinct, $column, $prefix);
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert into database
|
2015-09-14 20:51:23 +00:00
|
|
|
public static function insert($table, $data, $prefix = null)
|
|
|
|
{
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
return self::$database->insert($table, $data, $prefix);
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update in database
|
2015-09-14 20:51:23 +00:00
|
|
|
public static function update($table, $data, $prefix = null)
|
|
|
|
{
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
return self::$database->update($table, $data, $prefix);
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete from database
|
2015-09-14 20:51:23 +00:00
|
|
|
public static function delete($table, $data, $prefix = null)
|
|
|
|
{
|
2015-05-29 19:27:45 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
return self::$database->delete($table, $data, $prefix);
|
2015-05-29 19:27:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-05 00:03:15 +00:00
|
|
|
// Count from database
|
2015-09-14 20:51:23 +00:00
|
|
|
public static function count($table, $data = null, $prefix = null)
|
|
|
|
{
|
2015-07-05 00:03:15 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
return self::$database->count($table, $data, $prefix);
|
2015-07-05 00:03:15 +00:00
|
|
|
|
|
|
|
}
|
2015-05-29 19:27:45 +00:00
|
|
|
}
|