mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
add database directory
This commit is contained in:
@@ -205,6 +205,7 @@ class RedisCache {
|
|||||||
|
|
||||||
// Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour
|
// Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour
|
||||||
function cache_value($Key, $Value, $Duration = 3600){
|
function cache_value($Key, $Value, $Duration = 3600){
|
||||||
|
$Value = $this->serialize($Value);
|
||||||
// $this->set($Key,$Value, 0, $Duration);
|
// $this->set($Key,$Value, 0, $Duration);
|
||||||
$this->redis->set($Key, $Value, $Duration);
|
$this->redis->set($Key, $Value, $Duration);
|
||||||
$this->cacheWriteTimes++;
|
$this->cacheWriteTimes++;
|
||||||
@@ -273,6 +274,7 @@ class RedisCache {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
$Return = $this->redis->get($Key);
|
$Return = $this->redis->get($Key);
|
||||||
|
$Return = ! is_null($Return) ? $this->unserialize($Return) : null;
|
||||||
$this->cacheReadTimes++;
|
$this->cacheReadTimes++;
|
||||||
$this->keyHits['read'][$Key] = !$this->keyHits['read'][$Key] ? 1 : $this->keyHits['read'][$Key]+1;
|
$this->keyHits['read'][$Key] = !$this->keyHits['read'][$Key] ? 1 : $this->keyHits['read'][$Key]+1;
|
||||||
return $Return;
|
return $Return;
|
||||||
@@ -301,4 +303,26 @@ class RedisCache {
|
|||||||
function getKeyHits ($type='read') {
|
function getKeyHits ($type='read') {
|
||||||
return (array)$this->keyHits[$type];
|
return (array)$this->keyHits[$type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the value.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function serialize($value)
|
||||||
|
{
|
||||||
|
return is_numeric($value) && ! in_array($value, [INF, -INF]) && ! is_nan($value) ? $value : serialize($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unserialize the value.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function unserialize($value)
|
||||||
|
{
|
||||||
|
return is_numeric($value) ? $value : unserialize($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ $rootpath .= "/";
|
|||||||
require $rootpath . 'include/config.php';
|
require $rootpath . 'include/config.php';
|
||||||
require $rootpath . 'include/functions.php';
|
require $rootpath . 'include/functions.php';
|
||||||
|
|
||||||
require $rootpath . 'classes/interface_db.php';
|
require $rootpath . 'include/database/interface_db.php';
|
||||||
require $rootpath . 'classes/class_db_mysqli.php';
|
require $rootpath . 'include/database/class_db_mysqli.php';
|
||||||
require $rootpath . 'classes/class_db.php';
|
require $rootpath . 'include/database/class_db.php';
|
||||||
require $rootpath . 'include/functions_db.php';
|
require $rootpath . 'include/database/helpers.php';
|
||||||
|
require $rootpath . 'include/database/class_exception.php';
|
||||||
|
|
||||||
require $rootpath . 'include/core.php';
|
require $rootpath . 'include/core.php';
|
||||||
|
|||||||
@@ -44,7 +44,12 @@ class DB
|
|||||||
|
|
||||||
public function query(string $sql)
|
public function query(string $sql)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
return $this->driver->query($sql);
|
return $this->driver->query($sql);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new \DatabaseException($sql, $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function error()
|
public function error()
|
||||||
@@ -77,6 +82,11 @@ class DB
|
|||||||
return $this->driver->fetchRow($result);
|
return $this->driver->fetchRow($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fetchArray($result, $type = null)
|
||||||
|
{
|
||||||
|
return $this->driver->fetchArray($result, $type);
|
||||||
|
}
|
||||||
|
|
||||||
public function affectedRows()
|
public function affectedRows()
|
||||||
{
|
{
|
||||||
return $this->driver->affectedRows();
|
return $this->driver->affectedRows();
|
||||||
@@ -53,6 +53,14 @@ class DBMysqli implements DBInterface
|
|||||||
return $mysqliResult->fetch_row();
|
return $mysqliResult->fetch_row();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fetchArray($mysqliResult, $type): array|null
|
||||||
|
{
|
||||||
|
if (is_null($type)) {
|
||||||
|
$type = MYSQLI_BOTH;
|
||||||
|
}
|
||||||
|
return $mysqliResult->fetch_array($type);
|
||||||
|
}
|
||||||
|
|
||||||
public function affectedRows(): int
|
public function affectedRows(): int
|
||||||
{
|
{
|
||||||
return $this->mysqli->affected_rows;
|
return $this->mysqli->affected_rows;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DatabaseException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct($query, $message)
|
||||||
|
{
|
||||||
|
parent::__construct("$message [$query]");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -30,9 +30,9 @@ function mysql_num_rows($result)
|
|||||||
return DB::getInstance()->numRows($result);
|
return DB::getInstance()->numRows($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mysql_fetch_array($result)
|
function mysql_fetch_array($result, $type = null)
|
||||||
{
|
{
|
||||||
return DB::getInstance()->fetchAssoc($result);
|
return DB::getInstance()->fetchArray($result, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mysql_fetch_assoc($result)
|
function mysql_fetch_assoc($result)
|
||||||
@@ -18,6 +18,8 @@ interface DBInterface
|
|||||||
|
|
||||||
public function fetchRow($result): array|null;
|
public function fetchRow($result): array|null;
|
||||||
|
|
||||||
|
public function fetchArray($result, $type): array|null;
|
||||||
|
|
||||||
public function affectedRows(): int;
|
public function affectedRows(): int;
|
||||||
|
|
||||||
public function escapeString(string $string): string;
|
public function escapeString(string $string): string;
|
||||||
Reference in New Issue
Block a user