/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/database.php

  • Committer: Suren A. Chilingaryan
  • Date: 2018-04-13 03:41:51 UTC
  • Revision ID: csa@suren.me-20180413034151-ikhhrlgmsnv363d7
Connect to source database only when performing query (allows to reduce number of re-connections as we often create DATABASE object for technical reasons)

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 var $col_quote = "\"";
51
51
 var $tbl_quote = "";
52
52
 
 
53
 var $debug_sql = 0;
 
54
 
53
55
 const GLOBAL_QUERY = 0x0001;
54
56
 const SINGLE_RESULT = 0x0002;
55
57
 const FETCH_NUM = 0x0100;
62
64
        unset($this->server['charset']);
63
65
    }
64
66
 
65
 
    $this->ReConnect();
 
67
    if ($server['sqldrv']) $this->driver = $server['sqldrv'];
 
68
    else $this->driver = $server['driver'];
 
69
 
 
70
    // Connect on first query to avoid repetitions...
 
71
    //$this->ReConnect();
66
72
 }
67
73
 
68
74
 function ReConnect() {
78
84
        $pdo_opts[PDO::ATTR_PERSISTENT] = true;
79
85
    }
80
86
 
 
87
    if ($this->debug_sql) {
 
88
        echo " * Connecting to {$server['driver']}\n";
 
89
    }
 
90
 
81
91
     try {
82
92
        $this->odbc = false;
83
93
        
97
107
                
98
108
                if ($server['timeout']) {
99
109
                    if ($server['ping']) {
 
110
                        if ($this->debug_sql) {
 
111
                            echo " * Ping {$server['host']}\n";
 
112
                        }
 
113
 
100
114
                        if ((!is_array($server['ping']))&&((!$server['host'])||(!$server['port'])))
101
115
                            throw new ADEIException(translate("The ping-before-connection feature is requiring the database's host and port to be excplicitly specified."));
102
116
                            
158
172
#           echo "connected\n";
159
173
#           exit;
160
174
        }
161
 
        
162
 
        if ($server['sqldrv']) $this->driver = $server['sqldrv'];
163
 
        else $this->driver = $server['driver'];
164
175
        
165
176
            /* Single check for single scheme */
166
177
        switch ($this->driver) {
216
227
 
217
228
 
218
229
 function Query($sql, $flags = 0) {
219
 
//    echo $sql . "\n\n";
 
230
    if (!$this->dbh) 
 
231
        $this->ReConnect();
220
232
 
221
233
    if ((!$this->connected)&&(($flags&DATABASE::GLOBAL_QUERY)==0))
222
234
         throw new ADEIException(translate("The database is not specified"));
237
249
                }
238
250
            }
239
251
        } else {
 
252
            if ($this->debug_sql) {
 
253
                echo " * " . $sql . "\n";
 
254
            }
 
255
 
240
256
            //echo $sql . "\n\n";
241
257
            $resp = $this->dbh->query($sql);
242
258
            $resp->setFetchMode(($flags&DATABASE::FETCH_NUM)?PDO::FETCH_NUM:PDO::FETCH_ASSOC);
257
273
 }
258
274
 
259
275
 function Prepare($sql, $flags = 0) {
 
276
    if (!$this->dbh) 
 
277
        $this->ReConnect();
 
278
    
 
279
    if ($this->debug_sql) {
 
280
        echo " * " . $sql . "\n";
 
281
    }
 
282
 
260
283
    if ((!$this->connected)&&(($flags&DATABASE::GLOBAL_QUERY)==0))
261
284
         throw new ADEIException(translate("The database is not specified"));
262
285