SQLite добавлен режим работы
This commit is contained in:
1 parent
1763fd2b72
commit
a6d916c4ae
3 files changed
+26
-4
No files matched your search
+1
-1
@@ -26,7 +26,7 @@ if (User::isAuthorized()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(empty($arErrors)) {
|
if(empty($arErrors)) {
|
||||||
$userId = User::create($_REQUEST['login'], $_REQUEST['pass'], $_REQUEST['email'], $_REQUEST['name'], '/uploads/users/system.png');
|
$userId = User::create($_REQUEST['login'], $_REQUEST['pass'], $_REQUEST['email'], $_REQUEST['name']);
|
||||||
|
|
||||||
User::authorize($userId);
|
User::authorize($userId);
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
/**
|
/**
|
||||||
* ID последней добавленной записи
|
* ID последней добавленной записи
|
||||||
*
|
*
|
||||||
* @var int|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
private ?string $lastInsertId = null;
|
private ?string $lastInsertId = null;
|
||||||
|
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
*/
|
*/
|
||||||
public function __construct(string $db_server = DB_HOST, string $db_user = DB_USER, ?string $db_pass = DB_PASSWORD, string $db_name = DB_NAME)
|
public function __construct(string $db_server = DB_HOST, string $db_user = DB_USER, ?string $db_pass = DB_PASSWORD, string $db_name = DB_NAME)
|
||||||
{
|
{
|
||||||
|
if (DB_TYPE === DB_TYPE_SQL) {
|
||||||
$dsn = 'mysql:host=' . $db_server . ';dbname=' . $db_name . ';charset=utf8';
|
$dsn = 'mysql:host=' . $db_server . ';dbname=' . $db_name . ';charset=utf8';
|
||||||
$opt = [
|
$opt = [
|
||||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||||
@@ -56,7 +57,20 @@
|
|||||||
\PDO::ATTR_EMULATE_PREPARES => false,
|
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
];
|
];
|
||||||
$this->db = new \PDO($dsn, $db_user, $db_pass, $opt);
|
$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,12 +194,16 @@
|
|||||||
{
|
{
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
self::$quantity++;
|
self::$quantity++;
|
||||||
|
|
||||||
|
if(DB_TYPE === DB_TYPE_SQL) {
|
||||||
try {
|
try {
|
||||||
$stmt = $this->db->query($sql);
|
$stmt = $this->db->query($sql);
|
||||||
} catch (\Throwable $t) {
|
} catch (\Throwable $t) {
|
||||||
throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY);
|
throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY);
|
||||||
}
|
}
|
||||||
$this->lastInsertId = $this->db->lastInsertId() ?? null;
|
$this->lastInsertId = $this->db->lastInsertId() ?? null;
|
||||||
|
|
||||||
|
|
||||||
$endTime = microtime(true);
|
$endTime = microtime(true);
|
||||||
self::$workingTime += ($endTime - $startTime);
|
self::$workingTime += ($endTime - $startTime);
|
||||||
|
|
||||||
@@ -195,6 +213,10 @@
|
|||||||
$result = $stmt->fetchAll();
|
$result = $stmt->fetchAll();
|
||||||
return $result ?: null;
|
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
|
* @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());
|
Log::logToFile(__METHOD__, 'User.log', func_get_args());
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@
|
|||||||
'login' => $login,
|
'login' => $login,
|
||||||
'password' => self::passwordEncryption($password),
|
'password' => self::passwordEncryption($password),
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'image' => $image,
|
'image_id' => null,
|
||||||
'token' => '',
|
'token' => '',
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'last_active' => time(),
|
'last_active' => time(),
|
||||||
|
|||||||
Reference in new issue
Block a user