SQLite добавлен режим работы
This commit is contained in:
1 parent
1763fd2b72
commit
a6d916c4ae
3 files changed
+46
-24
No files matched your search
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* ID последней добавленной записи
|
||||
*
|
||||
* @var int|null
|
||||
* @var string|null
|
||||
*/
|
||||
private ?string $lastInsertId = null;
|
||||
|
||||
@@ -49,15 +49,29 @@
|
||||
*/
|
||||
public function __construct(string $db_server = DB_HOST, string $db_user = DB_USER, ?string $db_pass = DB_PASSWORD, string $db_name = DB_NAME)
|
||||
{
|
||||
$dsn = 'mysql:host=' . $db_server . ';dbname=' . $db_name . ';charset=utf8';
|
||||
$opt = [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||||
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
$this->db = new \PDO($dsn, $db_user, $db_pass, $opt);
|
||||
if (DB_TYPE === DB_TYPE_SQL) {
|
||||
$dsn = 'mysql:host=' . $db_server . ';dbname=' . $db_name . ';charset=utf8';
|
||||
$opt = [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
||||
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
$this->db = new \PDO($dsn, $db_user, $db_pass, $opt);
|
||||
} elseif (DB_TYPE === DB_TYPE_SQLITE) {
|
||||
$this->db = new \SQLite3(SQLITE_DB_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Деструктор
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
unset($this->instance);
|
||||
unset($this->db);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Получить объект класса
|
||||
*
|
||||
@@ -180,20 +194,28 @@
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
self::$quantity++;
|
||||
try {
|
||||
$stmt = $this->db->query($sql);
|
||||
} catch (\Throwable $t) {
|
||||
throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY);
|
||||
}
|
||||
$this->lastInsertId = $this->db->lastInsertId() ?? null;
|
||||
$endTime = microtime(true);
|
||||
self::$workingTime += ($endTime - $startTime);
|
||||
|
||||
if ($returnObject) {
|
||||
return $stmt;
|
||||
} else {
|
||||
$result = $stmt->fetchAll();
|
||||
return $result ?: null;
|
||||
if(DB_TYPE === DB_TYPE_SQL) {
|
||||
try {
|
||||
$stmt = $this->db->query($sql);
|
||||
} catch (\Throwable $t) {
|
||||
throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY);
|
||||
}
|
||||
$this->lastInsertId = $this->db->lastInsertId() ?? null;
|
||||
|
||||
|
||||
$endTime = microtime(true);
|
||||
self::$workingTime += ($endTime - $startTime);
|
||||
|
||||
if ($returnObject) {
|
||||
return $stmt;
|
||||
} else {
|
||||
$result = $stmt->fetchAll();
|
||||
return $result ?: null;
|
||||
}
|
||||
} elseif(DB_TYPE === DB_TYPE_SQLITE) {
|
||||
$result = $this->db->query($sql);
|
||||
return $result->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@
|
||||
*
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static function create(string $login, string $password, string $email, string $name = '', string $image = ''): int
|
||||
public static function create(string $login, string $password, string $email, string $name = ''): int
|
||||
{
|
||||
Log::logToFile(__METHOD__, 'User.log', func_get_args());
|
||||
|
||||
@@ -312,7 +312,7 @@
|
||||
'login' => $login,
|
||||
'password' => self::passwordEncryption($password),
|
||||
'name' => $name,
|
||||
'image' => $image,
|
||||
'image_id' => null,
|
||||
'token' => '',
|
||||
'email' => $email,
|
||||
'last_active' => time(),
|
||||
|
||||
Reference in new issue
Block a user