42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
$config = parse_ini_file(__DIR__ . '/../config/flashii.ini');
|
|
|
|
define('STR_CONFIG', $config['msz-config-path']);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
if(!is_file(STR_CONFIG)) {
|
|
http_response_code(500);
|
|
echo '{"error":101}';
|
|
exit;
|
|
}
|
|
|
|
$config = parse_ini_file(STR_CONFIG);
|
|
|
|
if(empty($config['driver']) || empty($config['unix_socket'])
|
|
|| empty($config['username']) || empty($config['database'])) {
|
|
http_response_code(500);
|
|
echo '{"error":102}';
|
|
exit;
|
|
}
|
|
|
|
if(empty($config['password']))
|
|
$config['password'] = '';
|
|
if(empty($config['charset']))
|
|
$config['charset'] = 'utf8mb4';
|
|
|
|
try {
|
|
$db = new PDO("{$config['driver']}:unix_socket={$config['unix_socket']};charset={$config['charset']};dbname={$config['database']}", $config['username'], $config['password'], [
|
|
PDO::ATTR_CASE => PDO::CASE_NATURAL,
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
|
PDO::ATTR_STRINGIFY_FETCHES => false,
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET SESSION time_zone = \'+00:00\''
|
|
. ', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'',
|
|
]);
|
|
} catch(PDOException $ex) {
|
|
http_response_code(500);
|
|
echo '{"error":103}';
|
|
exit;
|
|
}
|