Browse code

Ermögliche Socket-Angabe für Datenbankverbindung

schokokeks.org web services authored on 02/02/2014 05:46:02
Showing 3 changed files
... ...
@@ -21,10 +21,13 @@ require_once('inc/debug.php');
21 21
 
22 22
 class DB extends PDO {
23 23
   function __construct() {
24
-    $dsn = "mysql:host=".config('db_host');
24
+    $dsn = "mysql:host=".config('db_host', true);
25 25
     if (config('db_port', true)) {
26 26
       $dsn .= ';port='.config('db_port', true);
27 27
     }
28
+    if (config('db_socket', true)) {
29
+      $dsn = "mysql:unix_socket=".config('db_socket', true);
30
+    }
28 31
     $username = config('db_user', true);
29 32
     $password = config('db_pass', true);
30 33
     parent::__construct($dsn, $username, $password);
... ...
@@ -17,7 +17,13 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
17 17
 global $config;
18 18
 $config = array();
19 19
 
20
-$config['db_host'] = ':/var/run/mysqld/mysqld-sys.sock';
20
+// either...
21
+$config['db_socket'] = '/var/run/mysqld/mysqld-sys.sock';
22
+// ... or
23
+$config['db_host'] = '10.8.0.1';
24
+$config['db_port'] = 3307;
25
+// (socket is preferred if both are defined)
26
+
21 27
 $config['db_user'] = 'username';
22 28
 $config['db_pass'] = 'password';
23 29
 
... ...
@@ -37,6 +43,6 @@ $config['session_name'] = 'CONFIG_SCHOKOKEKS_ORG';
37 43
 $config['theme'] = 'default';
38 44
 $config['jquery_ui_path'] = 'https://source.schokokeks.org/external/jquery/jquery-ui-1.10.0/';
39 45
 
40
-ini_set('error_reporting','On');
46
+ini_set('display_errors','On');
41 47
 
42 48
 ?>
... ...
@@ -17,7 +17,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
17 17
 require_once('class/database.php');
18 18
 require_once('inc/debug.php');
19 19
 
20
-function config($key)
20
+function config($key, $localonly = false)
21 21
 {
22 22
   global $config;
23 23
 
... ...
@@ -35,6 +35,10 @@ function config($key)
35 35
   if (array_key_exists($key, $config))
36 36
     return $config[$key];
37 37
   
38
+  if ($localonly) {
39
+    return NULL;
40
+  }  
41
+
38 42
   /* read configuration from database */
39 43
   $result = db_query( "SELECT `key`, value FROM misc.config" );
40 44