source: trunk/forum/includes/db/dbal.php@ 482

Last change on this file since 482 was 400, checked in by george, 16 years ago
  • Přidáno: Nové forum phpBB 3.
File size: 21.6 KB
Line 
1<?php
2/**
3*
4* @package dbal
5* @version $Id: dbal.php 9178 2008-12-06 11:11:10Z acydburn $
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* Database Abstraction Layer
21* @package dbal
22*/
23class dbal
24{
25 var $db_connect_id;
26 var $query_result;
27 var $return_on_error = false;
28 var $transaction = false;
29 var $sql_time = 0;
30 var $num_queries = array();
31 var $open_queries = array();
32
33 var $curtime = 0;
34 var $query_hold = '';
35 var $html_hold = '';
36 var $sql_report = '';
37
38 var $persistency = false;
39 var $user = '';
40 var $server = '';
41 var $dbname = '';
42
43 // Set to true if error triggered
44 var $sql_error_triggered = false;
45
46 // Holding the last sql query on sql error
47 var $sql_error_sql = '';
48 // Holding the error information - only populated if sql_error_triggered is set
49 var $sql_error_returned = array();
50
51 // Holding transaction count
52 var $transactions = 0;
53
54 // Supports multi inserts?
55 var $multi_insert = false;
56
57 /**
58 * Current sql layer
59 */
60 var $sql_layer = '';
61
62 /**
63 * Wildcards for matching any (%) or exactly one (_) character within LIKE expressions
64 */
65 var $any_char;
66 var $one_char;
67
68 /**
69 * Exact version of the DBAL, directly queried
70 */
71 var $sql_server_version = false;
72
73 /**
74 * Constructor
75 */
76 function dbal()
77 {
78 $this->num_queries = array(
79 'cached' => 0,
80 'normal' => 0,
81 'total' => 0,
82 );
83
84 // Fill default sql layer based on the class being called.
85 // This can be changed by the specified layer itself later if needed.
86 $this->sql_layer = substr(get_class($this), 5);
87
88 // Do not change this please! This variable is used to easy the use of it - and is hardcoded.
89 $this->any_char = chr(0) . '%';
90 $this->one_char = chr(0) . '_';
91 }
92
93 /**
94 * return on error or display error message
95 */
96 function sql_return_on_error($fail = false)
97 {
98 $this->sql_error_triggered = false;
99 $this->sql_error_sql = '';
100
101 $this->return_on_error = $fail;
102 }
103
104 /**
105 * Return number of sql queries and cached sql queries used
106 */
107 function sql_num_queries($cached = false)
108 {
109 return ($cached) ? $this->num_queries['cached'] : $this->num_queries['normal'];
110 }
111
112 /**
113 * Add to query count
114 */
115 function sql_add_num_queries($cached = false)
116 {
117 $this->num_queries['cached'] += ($cached !== false) ? 1 : 0;
118 $this->num_queries['normal'] += ($cached !== false) ? 0 : 1;
119 $this->num_queries['total'] += 1;
120 }
121
122 /**
123 * DBAL garbage collection, close sql connection
124 */
125 function sql_close()
126 {
127 if (!$this->db_connect_id)
128 {
129 return false;
130 }
131
132 if ($this->transaction)
133 {
134 do
135 {
136 $this->sql_transaction('commit');
137 }
138 while ($this->transaction);
139 }
140
141 foreach ($this->open_queries as $query_id)
142 {
143 $this->sql_freeresult($query_id);
144 }
145
146 // Connection closed correctly. Set db_connect_id to false to prevent errors
147 if ($result = $this->_sql_close())
148 {
149 $this->db_connect_id = false;
150 }
151
152 return $result;
153 }
154
155 /**
156 * Build LIMIT query
157 * Doing some validation here.
158 */
159 function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
160 {
161 if (empty($query))
162 {
163 return false;
164 }
165
166 // Never use a negative total or offset
167 $total = ($total < 0) ? 0 : $total;
168 $offset = ($offset < 0) ? 0 : $offset;
169
170 return $this->_sql_query_limit($query, $total, $offset, $cache_ttl);
171 }
172
173 /**
174 * Fetch all rows
175 */
176 function sql_fetchrowset($query_id = false)
177 {
178 if ($query_id === false)
179 {
180 $query_id = $this->query_result;
181 }
182
183 if ($query_id !== false)
184 {
185 $result = array();
186 while ($row = $this->sql_fetchrow($query_id))
187 {
188 $result[] = $row;
189 }
190
191 return $result;
192 }
193
194 return false;
195 }
196
197 /**
198 * Fetch field
199 * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
200 */
201 function sql_fetchfield($field, $rownum = false, $query_id = false)
202 {
203 global $cache;
204
205 if ($query_id === false)
206 {
207 $query_id = $this->query_result;
208 }
209
210 if ($query_id !== false)
211 {
212 if ($rownum !== false)
213 {
214 $this->sql_rowseek($rownum, $query_id);
215 }
216
217 if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
218 {
219 return $cache->sql_fetchfield($query_id, $field);
220 }
221
222 $row = $this->sql_fetchrow($query_id);
223 return (isset($row[$field])) ? $row[$field] : false;
224 }
225
226 return false;
227 }
228
229 /**
230 * Correctly adjust LIKE expression for special characters
231 * Some DBMS are handling them in a different way
232 *
233 * @param string $expression The expression to use. Every wildcard is escaped, except $this->any_char and $this->one_char
234 * @return string LIKE expression including the keyword!
235 */
236 function sql_like_expression($expression)
237 {
238 $expression = str_replace(array('_', '%'), array("\_", "\%"), $expression);
239 $expression = str_replace(array(chr(0) . "\_", chr(0) . "\%"), array('_', '%'), $expression);
240
241 return $this->_sql_like_expression('LIKE \'' . $this->sql_escape($expression) . '\'');
242 }
243
244 /**
245 * SQL Transaction
246 * @access private
247 */
248 function sql_transaction($status = 'begin')
249 {
250 switch ($status)
251 {
252 case 'begin':
253 // If we are within a transaction we will not open another one, but enclose the current one to not loose data (prevening auto commit)
254 if ($this->transaction)
255 {
256 $this->transactions++;
257 return true;
258 }
259
260 $result = $this->_sql_transaction('begin');
261
262 if (!$result)
263 {
264 $this->sql_error();
265 }
266
267 $this->transaction = true;
268 break;
269
270 case 'commit':
271 // If there was a previously opened transaction we do not commit yet... but count back the number of inner transactions
272 if ($this->transaction && $this->transactions)
273 {
274 $this->transactions--;
275 return true;
276 }
277
278 // Check if there is a transaction (no transaction can happen if there was an error, with a combined rollback and error returning enabled)
279 // This implies we have transaction always set for autocommit db's
280 if (!$this->transaction)
281 {
282 return false;
283 }
284
285 $result = $this->_sql_transaction('commit');
286
287 if (!$result)
288 {
289 $this->sql_error();
290 }
291
292 $this->transaction = false;
293 $this->transactions = 0;
294 break;
295
296 case 'rollback':
297 $result = $this->_sql_transaction('rollback');
298 $this->transaction = false;
299 $this->transactions = 0;
300 break;
301
302 default:
303 $result = $this->_sql_transaction($status);
304 break;
305 }
306
307 return $result;
308 }
309
310 /**
311 * Build sql statement from array for insert/update/select statements
312 *
313 * Idea for this from Ikonboard
314 * Possible query values: INSERT, INSERT_SELECT, UPDATE, SELECT
315 *
316 */
317 function sql_build_array($query, $assoc_ary = false)
318 {
319 if (!is_array($assoc_ary))
320 {
321 return false;
322 }
323
324 $fields = $values = array();
325
326 if ($query == 'INSERT' || $query == 'INSERT_SELECT')
327 {
328 foreach ($assoc_ary as $key => $var)
329 {
330 $fields[] = $key;
331
332 if (is_array($var) && is_string($var[0]))
333 {
334 // This is used for INSERT_SELECT(s)
335 $values[] = $var[0];
336 }
337 else
338 {
339 $values[] = $this->_sql_validate_value($var);
340 }
341 }
342
343 $query = ($query == 'INSERT') ? ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')' : ' (' . implode(', ', $fields) . ') SELECT ' . implode(', ', $values) . ' ';
344 }
345 else if ($query == 'MULTI_INSERT')
346 {
347 trigger_error('The MULTI_INSERT query value is no longer supported. Please use sql_multi_insert() instead.', E_USER_ERROR);
348 }
349 else if ($query == 'UPDATE' || $query == 'SELECT')
350 {
351 $values = array();
352 foreach ($assoc_ary as $key => $var)
353 {
354 $values[] = "$key = " . $this->_sql_validate_value($var);
355 }
356 $query = implode(($query == 'UPDATE') ? ', ' : ' AND ', $values);
357 }
358
359 return $query;
360 }
361
362 /**
363 * Build IN or NOT IN sql comparison string, uses <> or = on single element
364 * arrays to improve comparison speed
365 *
366 * @access public
367 * @param string $field name of the sql column that shall be compared
368 * @param array $array array of values that are allowed (IN) or not allowed (NOT IN)
369 * @param bool $negate true for NOT IN (), false for IN () (default)
370 * @param bool $allow_empty_set If true, allow $array to be empty, this function will return 1=1 or 1=0 then. Default to false.
371 */
372 function sql_in_set($field, $array, $negate = false, $allow_empty_set = false)
373 {
374 if (!sizeof($array))
375 {
376 if (!$allow_empty_set)
377 {
378 // Print the backtrace to help identifying the location of the problematic code
379 $this->sql_error('No values specified for SQL IN comparison');
380 }
381 else
382 {
383 // NOT IN () actually means everything so use a tautology
384 if ($negate)
385 {
386 return '1=1';
387 }
388 // IN () actually means nothing so use a contradiction
389 else
390 {
391 return '1=0';
392 }
393 }
394 }
395
396 if (!is_array($array))
397 {
398 $array = array($array);
399 }
400
401 if (sizeof($array) == 1)
402 {
403 @reset($array);
404 $var = current($array);
405
406 return $field . ($negate ? ' <> ' : ' = ') . $this->_sql_validate_value($var);
407 }
408 else
409 {
410 return $field . ($negate ? ' NOT IN ' : ' IN ') . '(' . implode(', ', array_map(array($this, '_sql_validate_value'), $array)) . ')';
411 }
412 }
413
414 /**
415 * Run more than one insert statement.
416 *
417 * @param string $table table name to run the statements on
418 * @param array &$sql_ary multi-dimensional array holding the statement data.
419 *
420 * @return bool false if no statements were executed.
421 * @access public
422 */
423 function sql_multi_insert($table, &$sql_ary)
424 {
425 if (!sizeof($sql_ary))
426 {
427 return false;
428 }
429
430 if ($this->multi_insert)
431 {
432 $ary = array();
433 foreach ($sql_ary as $id => $_sql_ary)
434 {
435 // If by accident the sql array is only one-dimensional we build a normal insert statement
436 if (!is_array($_sql_ary))
437 {
438 $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary));
439 return true;
440 }
441
442 $values = array();
443 foreach ($_sql_ary as $key => $var)
444 {
445 $values[] = $this->_sql_validate_value($var);
446 }
447 $ary[] = '(' . implode(', ', $values) . ')';
448 }
449
450 $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary));
451 }
452 else
453 {
454 foreach ($sql_ary as $ary)
455 {
456 if (!is_array($ary))
457 {
458 return false;
459 }
460
461 $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary));
462 }
463 }
464
465 return true;
466 }
467
468 /**
469 * Function for validating values
470 * @access private
471 */
472 function _sql_validate_value($var)
473 {
474 if (is_null($var))
475 {
476 return 'NULL';
477 }
478 else if (is_string($var))
479 {
480 return "'" . $this->sql_escape($var) . "'";
481 }
482 else
483 {
484 return (is_bool($var)) ? intval($var) : $var;
485 }
486 }
487
488 /**
489 * Build sql statement from array for select and select distinct statements
490 *
491 * Possible query values: SELECT, SELECT_DISTINCT
492 */
493 function sql_build_query($query, $array)
494 {
495 $sql = '';
496 switch ($query)
497 {
498 case 'SELECT':
499 case 'SELECT_DISTINCT';
500
501 $sql = str_replace('_', ' ', $query) . ' ' . $array['SELECT'] . ' FROM ';
502
503 // Build table array. We also build an alias array for later checks.
504 $table_array = $aliases = array();
505 $used_multi_alias = false;
506
507 foreach ($array['FROM'] as $table_name => $alias)
508 {
509 if (is_array($alias))
510 {
511 $used_multi_alias = true;
512
513 foreach ($alias as $multi_alias)
514 {
515 $table_array[] = $table_name . ' ' . $multi_alias;
516 $aliases[] = $multi_alias;
517 }
518 }
519 else
520 {
521 $table_array[] = $table_name . ' ' . $alias;
522 $aliases[] = $alias;
523 }
524 }
525
526 // We run the following code to determine if we need to re-order the table array. ;)
527 // The reason for this is that for multi-aliased tables (two equal tables) in the FROM statement the last table need to match the first comparison.
528 // DBMS who rely on this: Oracle, PostgreSQL and MSSQL. For all other DBMS it makes absolutely no difference in which order the table is.
529 if (!empty($array['LEFT_JOIN']) && sizeof($array['FROM']) > 1 && $used_multi_alias !== false)
530 {
531 // Take first LEFT JOIN
532 $join = current($array['LEFT_JOIN']);
533
534 // Determine the table used there (even if there are more than one used, we only want to have one
535 preg_match('/(' . implode('|', $aliases) . ')\.[^\s]+/U', str_replace(array('(', ')', 'AND', 'OR', ' '), '', $join['ON']), $matches);
536
537 // If there is a first join match, we need to make sure the table order is correct
538 if (!empty($matches[1]))
539 {
540 $first_join_match = trim($matches[1]);
541 $table_array = $last = array();
542
543 foreach ($array['FROM'] as $table_name => $alias)
544 {
545 if (is_array($alias))
546 {
547 foreach ($alias as $multi_alias)
548 {
549 ($multi_alias === $first_join_match) ? $last[] = $table_name . ' ' . $multi_alias : $table_array[] = $table_name . ' ' . $multi_alias;
550 }
551 }
552 else
553 {
554 ($alias === $first_join_match) ? $last[] = $table_name . ' ' . $alias : $table_array[] = $table_name . ' ' . $alias;
555 }
556 }
557
558 $table_array = array_merge($table_array, $last);
559 }
560 }
561
562 $sql .= $this->_sql_custom_build('FROM', implode(', ', $table_array));
563
564 if (!empty($array['LEFT_JOIN']))
565 {
566 foreach ($array['LEFT_JOIN'] as $join)
567 {
568 $sql .= ' LEFT JOIN ' . key($join['FROM']) . ' ' . current($join['FROM']) . ' ON (' . $join['ON'] . ')';
569 }
570 }
571
572 if (!empty($array['WHERE']))
573 {
574 $sql .= ' WHERE ' . $this->_sql_custom_build('WHERE', $array['WHERE']);
575 }
576
577 if (!empty($array['GROUP_BY']))
578 {
579 $sql .= ' GROUP BY ' . $array['GROUP_BY'];
580 }
581
582 if (!empty($array['ORDER_BY']))
583 {
584 $sql .= ' ORDER BY ' . $array['ORDER_BY'];
585 }
586
587 break;
588 }
589
590 return $sql;
591 }
592
593 /**
594 * display sql error page
595 */
596 function sql_error($sql = '')
597 {
598 global $auth, $user, $config;
599
600 // Set var to retrieve errored status
601 $this->sql_error_triggered = true;
602 $this->sql_error_sql = $sql;
603
604 $this->sql_error_returned = $this->_sql_error();
605
606 if (!$this->return_on_error)
607 {
608 $message = 'SQL ERROR [ ' . $this->sql_layer . ' ]<br /><br />' . $this->sql_error_returned['message'] . ' [' . $this->sql_error_returned['code'] . ']';
609
610 // Show complete SQL error and path to administrators only
611 // Additionally show complete error on installation or if extended debug mode is enabled
612 // The DEBUG_EXTRA constant is for development only!
613 if ((isset($auth) && $auth->acl_get('a_')) || defined('IN_INSTALL') || defined('DEBUG_EXTRA'))
614 {
615 // Print out a nice backtrace...
616 $backtrace = get_backtrace();
617
618 $message .= ($sql) ? '<br /><br />SQL<br /><br />' . htmlspecialchars($sql) : '';
619 $message .= ($backtrace) ? '<br /><br />BACKTRACE<br />' . $backtrace : '';
620 $message .= '<br />';
621 }
622 else
623 {
624 // If error occurs in initiating the session we need to use a pre-defined language string
625 // This could happen if the connection could not be established for example (then we are not able to grab the default language)
626 if (!isset($user->lang['SQL_ERROR_OCCURRED']))
627 {
628 $message .= '<br /><br />An sql error occurred while fetching this page. Please contact an administrator if this problem persists.';
629 }
630 else
631 {
632 if (!empty($config['board_contact']))
633 {
634 $message .= '<br /><br />' . sprintf($user->lang['SQL_ERROR_OCCURRED'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>');
635 }
636 else
637 {
638 $message .= '<br /><br />' . sprintf($user->lang['SQL_ERROR_OCCURRED'], '', '');
639 }
640 }
641 }
642
643 if ($this->transaction)
644 {
645 $this->sql_transaction('rollback');
646 }
647
648 if (strlen($message) > 1024)
649 {
650 // We need to define $msg_long_text here to circumvent text stripping.
651 global $msg_long_text;
652 $msg_long_text = $message;
653
654 trigger_error(false, E_USER_ERROR);
655 }
656
657 trigger_error($message, E_USER_ERROR);
658 }
659
660 if ($this->transaction)
661 {
662 $this->sql_transaction('rollback');
663 }
664
665 return $this->sql_error_returned;
666 }
667
668 /**
669 * Explain queries
670 */
671 function sql_report($mode, $query = '')
672 {
673 global $cache, $starttime, $phpbb_root_path, $user;
674
675 if (empty($_REQUEST['explain']))
676 {
677 return false;
678 }
679
680 if (!$query && $this->query_hold != '')
681 {
682 $query = $this->query_hold;
683 }
684
685 switch ($mode)
686 {
687 case 'display':
688 if (!empty($cache))
689 {
690 $cache->unload();
691 }
692 $this->sql_close();
693
694 $mtime = explode(' ', microtime());
695 $totaltime = $mtime[0] + $mtime[1] - $starttime;
696
697 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
698 <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
699 <head>
700 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
701 <meta http-equiv="Content-Style-Type" content="text/css" />
702 <meta http-equiv="imagetoolbar" content="no" />
703 <title>SQL Report</title>
704 <link href="' . $phpbb_root_path . 'adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
705 </head>
706 <body id="errorpage">
707 <div id="wrap">
708 <div id="page-header">
709 <a href="' . build_url('explain') . '">Return to previous page</a>
710 </div>
711 <div id="page-body">
712 <div id="acp">
713 <div class="panel">
714 <span class="corners-top"><span></span></span>
715 <div id="content">
716 <h1>SQL Report</h1>
717 <br />
718 <p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries['normal']} queries" . (($this->num_queries['cached']) ? " + {$this->num_queries['cached']} " . (($this->num_queries['cached'] == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p>
719
720 <p>Time spent on ' . $this->sql_layer . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p>
721
722 <br /><br />
723 ' . $this->sql_report . '
724 </div>
725 <span class="corners-bottom"><span></span></span>
726 </div>
727 </div>
728 </div>
729 <div id="page-footer">
730 Powered by phpBB &copy; 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>
731 </div>
732 </div>
733 </body>
734 </html>';
735
736 exit_handler();
737
738 break;
739
740 case 'stop':
741 $endtime = explode(' ', microtime());
742 $endtime = $endtime[0] + $endtime[1];
743
744 $this->sql_report .= '
745
746 <table cellspacing="1">
747 <thead>
748 <tr>
749 <th>Query #' . $this->num_queries['total'] . '</th>
750 </tr>
751 </thead>
752 <tbody>
753 <tr>
754 <td class="row3"><textarea style="font-family:\'Courier New\',monospace;width:99%" rows="5" cols="10">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td>
755 </tr>
756 </tbody>
757 </table>
758
759 ' . $this->html_hold . '
760
761 <p style="text-align: center;">
762 ';
763
764 if ($this->query_result)
765 {
766 if (preg_match('/^(UPDATE|DELETE|REPLACE)/', $query))
767 {
768 $this->sql_report .= 'Affected rows: <b>' . $this->sql_affectedrows($this->query_result) . '</b> | ';
769 }
770 $this->sql_report .= 'Before: ' . sprintf('%.5f', $this->curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed: <b>' . sprintf('%.5f', $endtime - $this->curtime) . 's</b>';
771 }
772 else
773 {
774 $error = $this->sql_error();
775 $this->sql_report .= '<b style="color: red">FAILED</b> - ' . $this->sql_layer . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']);
776 }
777
778 $this->sql_report .= '</p><br /><br />';
779
780 $this->sql_time += $endtime - $this->curtime;
781 break;
782
783 case 'start':
784 $this->query_hold = $query;
785 $this->html_hold = '';
786
787 $this->_sql_report($mode, $query);
788
789 $this->curtime = explode(' ', microtime());
790 $this->curtime = $this->curtime[0] + $this->curtime[1];
791
792 break;
793
794 case 'add_select_row':
795
796 $html_table = func_get_arg(2);
797 $row = func_get_arg(3);
798
799 if (!$html_table && sizeof($row))
800 {
801 $html_table = true;
802 $this->html_hold .= '<table cellspacing="1"><tr>';
803
804 foreach (array_keys($row) as $val)
805 {
806 $this->html_hold .= '<th>' . (($val) ? ucwords(str_replace('_', ' ', $val)) : '&nbsp;') . '</th>';
807 }
808 $this->html_hold .= '</tr>';
809 }
810 $this->html_hold .= '<tr>';
811
812 $class = 'row1';
813 foreach (array_values($row) as $val)
814 {
815 $class = ($class == 'row1') ? 'row2' : 'row1';
816 $this->html_hold .= '<td class="' . $class . '">' . (($val) ? $val : '&nbsp;') . '</td>';
817 }
818 $this->html_hold .= '</tr>';
819
820 return $html_table;
821
822 break;
823
824 case 'fromcache':
825
826 $this->_sql_report($mode, $query);
827
828 break;
829
830 case 'record_fromcache':
831
832 $endtime = func_get_arg(2);
833 $splittime = func_get_arg(3);
834
835 $time_cache = $endtime - $this->curtime;
836 $time_db = $splittime - $endtime;
837 $color = ($time_db > $time_cache) ? 'green' : 'red';
838
839 $this->sql_report .= '<table cellspacing="1"><thead><tr><th>Query results obtained from the cache</th></tr></thead><tbody><tr>';
840 $this->sql_report .= '<td class="row3"><textarea style="font-family:\'Courier New\',monospace;width:99%" rows="5" cols="10">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td></tr></tbody></table>';
841 $this->sql_report .= '<p style="text-align: center;">';
842 $this->sql_report .= 'Before: ' . sprintf('%.5f', $this->curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed [cache]: <b style="color: ' . $color . '">' . sprintf('%.5f', ($time_cache)) . 's</b> | Elapsed [db]: <b>' . sprintf('%.5f', $time_db) . 's</b></p><br /><br />';
843
844 // Pad the start time to not interfere with page timing
845 $starttime += $time_db;
846
847 break;
848
849 default:
850
851 $this->_sql_report($mode, $query);
852
853 break;
854 }
855
856 return true;
857 }
858}
859
860/**
861* This variable holds the class name to use later
862*/
863$sql_db = (!empty($dbms)) ? 'dbal_' . basename($dbms) : 'dbal';
864
865?>
Note: See TracBrowser for help on using the repository browser.