]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - plugins/sql_auth/SQL/sql.php
Move to new style config, with config in config/ directory.
[irc/unrealircd/unrealircd-webpanel.git] / plugins / sql_auth / SQL / sql.php
1 <?php
2
3 function sqlnew()
4 {
5 $host = get_config("mysql::host");
6 $user = get_config("mysql::username");
7 $pass = get_config("mysql::password");
8 $db = get_config("mysql::database");
9 $charset = 'utf8mb4';
10
11 if ($host[0] == "/")
12 $host_type = "unix_socket";
13 else
14 $host_type = "host";
15 $dsn = "mysql:$host_type=$host;dbname=$db;charset=$charset";
16 $options = [
17 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
18 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
19 PDO::ATTR_EMULATE_PREPARES => false,
20 ];
21 try {
22 $pdo = new PDO($dsn, $user, $pass, $options);
23 } catch (\PDOException $e) {
24 throw new \PDOException($e->getMessage(), (int)$e->getCode());
25 }
26 return $pdo;
27 }