Mass update
This commit is contained in:
@@ -1,34 +1,44 @@
|
||||
<?php
|
||||
|
||||
# Let's hope it will work.
|
||||
|
||||
namespace Core;
|
||||
|
||||
use PDO;
|
||||
|
||||
class Database
|
||||
{
|
||||
private const DB = 'newcom1_abk';
|
||||
private const USER = 'newcom1_abk';
|
||||
private const PASSWORD = '4nWYsIM[c?}P';
|
||||
private const DSN = 'mysql:host=localhost;dbname=' . self::DB;
|
||||
private static self $instance;
|
||||
protected static PDO $db;
|
||||
|
||||
//todo: remove PDO from files and connect through new pdoinit().
|
||||
public static function init(): PDO
|
||||
{
|
||||
|
||||
mysql_select_db(self::DB, mysql_connect('localhost', self::USER, self::PASSWORD));
|
||||
/**
|
||||
* Singleton.
|
||||
*/
|
||||
private function __construct() {
|
||||
mysql_select_db(Config::get('db_name'), mysql_connect('localhost', Config::get('db_user'), Config::get('db_password')));
|
||||
mysql_query('SET NAMES cp1251');
|
||||
|
||||
return self::pdoinit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Для совместимости со старыми функциями mysql_*.
|
||||
* @return Database
|
||||
*/
|
||||
public static function init(): Database
|
||||
{
|
||||
if (!isset(self::$instance)) {
|
||||
self::$instance = new static();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Новое подключение к БД.
|
||||
* @return PDO
|
||||
*/
|
||||
public static function pdoinit(): PDO
|
||||
{
|
||||
return new PDO(
|
||||
self::DSN,
|
||||
self::USER,
|
||||
self::PASSWORD,
|
||||
'mysql:host=localhost;dbname=' . Config::get('db_name'),
|
||||
Config::get('db_user'),
|
||||
Config::get('db_password'),
|
||||
[
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
|
||||
Reference in New Issue
Block a user