/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to classes/adeidb.php

  • Committer: Suren A. Chilingaryan
  • Date: 2018-03-21 16:21:54 UTC
  • Revision ID: csa@suren.me-20180321162154-w138wtbfi1uy8ma3
Various improvements for OpenShift operation

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
 static function ConnectDB() {
20
20
    global $ADEI_DB;
 
21
    global $ADEI_CACHE_ENGINE;
21
22
 
22
23
    $dbh = mysql_connect($ADEI_DB['host'] . ($ADEI_DB['port']?(":" . $ADEI_DB['port']):""), $ADEI_DB['user'], $ADEI_DB['password']);
23
24
    if (!$dbh) throw new ADEIException(translate("Connection to the Caching MySQL Server is failed"));
25
26
    mysql_query("SET sql_mode = ''", $dbh);
26
27
    mysql_query("SET time_zone = '+0:00'", $dbh);
27
28
 
 
29
            // We expect that INNODB is used if replication is on...
 
30
    if (!strcasecmp($ADEI_CACHE_ENGINE, "MYISAM")) {
 
31
        mysql_query("SET sql_log_bin = 0", $dbh);
 
32
    }
 
33
        // We don't need syncing even if INNODB and replication is used, re-caching couple of last minutes is completely fine
 
34
    mysql_query("SET sync_binlog = 0", $dbh);
 
35
 
 
36
 
28
37
    if (!@mysql_select_db($ADEI_DB['database'], $dbh)) {
29
38
                // ER_NO_DB_ERROR
30
39
        if (mysql_errno($dbh) == CACHEDB::MYSQL_ER_BAD_DB_ERROR) { 
31
 
            if (mysql_query("CREATE DATABASE " . $ADEI_DB['database'], $dbh)) {
 
40
            if (mysql_query("CREATE DATABASE IF NOT EXISTS " . $ADEI_DB['database'], $dbh)) {
32
41
                if (!mysql_select_db($ADEI_DB['database'], $dbh))
33
42
                    throw new ADEIException(translate("Connection to the Caching MySQL Database is failed") . " (" . mysql_error($dbh) . ")");
34
43
 
60
69
    }
61
70
 }
62
71
 
 
72
 function LockCachingTable($table) {
 
73
    mysql_query("LOCK TABLES $table WRITE");
 
74
 }
 
75
 
 
76
 function UnLockCache() {
 
77
    mysql_query("UNLOCK TABLES");
 
78
 }
 
79
 
63
80
 function CreateTable($name, $spec) {
64
 
    if (!@mysql_query("CREATE TABLE `$name` ($spec)", $this->dbh)) {
 
81
    if (!@mysql_query("CREATE TABLE IF NOT EXIST `$name` ($spec)", $this->dbh)) {
65
82
        throw new ADEIException(translate("Creation of system table (%s) within CACHE database is failed", $name) . " (" . mysql_error($this->dbh) . ")");
66
83
    }
67
84
 }