3 V4.20 22 Feb 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
4 Released under both BSD license and Lesser GPL library license.
5 Whenever there is any discrepancy between the two licenses,
6 the BSD license will take precedence. See License.txt.
7 Set tabs to 4 for best viewing.
9 Latest version is available at http://php.weblogs.com/
11 Library for basic performance monitoring and tuning.
13 My apologies if you see code mixed with presentation. The presentation suits
14 my needs. If you want to separate code from presentation, be my guest. Patches
19 if (!defined(ADODB_DIR
)) include_once(dirname(__FILE__
).'/adodb.inc.php');
20 include_once(ADODB_DIR
.'/tohtml.inc.php');
23 /* return microtime value as a float */
24 function adodb_microtime()
28 return (float)$t[1]+
(float)$t[0];
32 function& adodb_log_sql(&$conn,$sql,$inputarr)
34 global $HTTP_SERVER_VARS;
36 $perf_table = adodb_perf
::table();
37 $conn->fnExecute
= false;
39 $rs =& $conn->Execute($sql,$inputarr);
42 if (!empty($conn->_logsql
)) {
43 $conn->_logsql
= false; // disable logsql error simulation
44 $dbT = $conn->databaseType
;
47 $a0 = (float)$a0[1]+
(float)$a0[0];
50 $a1 = (float)$a1[1]+
(float)$a1[0];
55 $errM = $conn->ErrorMsg();
56 $errN = $conn->ErrorNo();
58 $tracer = substr('ERROR: '.htmlspecialchars($errM),0,250);
65 if (!is_object($rs) ||
$rs->dataProvider
== 'empty')
66 $conn->_affected
= $conn->affected_rows(true);
67 $conn->lastInsID
= @$conn->Insert_ID();
70 if (isset($HTTP_SERVER_VARS['HTTP_HOST'])) {
71 $tracer .= '<br>'.$HTTP_SERVER_VARS['HTTP_HOST'];
72 if (isset($HTTP_SERVER_VARS['PHP_SELF'])) $tracer .= $HTTP_SERVER_VARS['PHP_SELF'];
74 if (isset($HTTP_SERVER_VARS['PHP_SELF'])) $tracer .= '<br>'.$HTTP_SERVER_VARS['PHP_SELF'];
75 //$tracer .= (string) adodb_backtrace(false);
77 $tracer = substr($tracer,0,500);
79 if (is_array($inputarr)) {
80 if (is_array(reset($inputarr))) $params = 'Array sizeof='.sizeof($inputarr);
83 $params = implode(', ',$inputarr);
84 if (strlen($params) >= 3000) $params = substr($params, 0, 3000);
90 if (is_array($sql)) $sql = $sql[0];
91 $arr = array('b'=>trim(substr($sql,0,230)),
92 'c'=>substr($sql,0,3900), 'd'=>$params,'e'=>$tracer,'f'=>round($time,6));
94 $saved = $conn->debug
;
97 if ($conn->dataProvider
== 'oci8' && $dbT != 'oci8po') {
98 $isql = "insert into $perf_table values($conn->sysTimeStamp,:b,:c,:d,:e,:f)";
99 } else if ($dbT == 'odbc_mssql' ||
$dbT == 'informix') {
101 if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
103 $sql1 = $conn->qstr($arr['b']);
104 $sql2 = $conn->qstr($arr['c']);
105 $params = $conn->qstr($arr['d']);
106 $tracer = $conn->qstr($arr['e']);
108 $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($conn->sysTimeStamp,$sql1,$sql2,$params,$tracer,$timer)";
109 if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
112 $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $conn->sysTimeStamp,?,?,?,?,?)";
114 $ok = $conn->Execute($isql,$arr);
115 $conn->debug
= $saved;
118 $conn->_logsql
= true;
120 $err2 = $conn->ErrorMsg();
121 $conn->_logsql
= true; // enable logsql error simulation
122 $perf =& NewPerfMonitor($conn);
124 if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr);
126 $ok = $conn->Execute("create table $perf_table (
130 params varchar(3000),
132 timer decimal(16,6))");
135 ADOConnection
::outp( "<b>LOGSQL Insert Failed</b>: $isql<br>$err2</br>");
136 $conn->_logsql
= false;
139 $conn->_errorMsg
= $errM;
140 $conn->_errorCode
= $errN;
142 $conn->fnExecute
= 'adodb_log_sql';
148 The settings data structure is an associative array that database parameter per element.
150 Each database parameter element in the array is itself an array consisting of:
152 0: category code, used to group related db parameters
154 a. sql string to retrieve value, eg. "select value from v\$parameter where name='db_block_size'",
155 b. array holding sql string and field to look for, e.g. array('show variables','table_cache'),
156 c. a string prefixed by =, then a PHP method of the class is invoked,
157 e.g. to invoke $this->GetIndexValue(), set this array element to '=GetIndexValue',
158 2: description of the database parameter
163 var $color = '#F0F0F0';
164 var $table = '<table border=1 bgcolor=white>';
165 var $titles = '<tr><td><b>Parameter</b></td><td><b>Value</b></td><td><b>Description</b></td></tr>';
167 var $tablesSQL = false;
168 var $cliFormat = "%32s => %s \r\n";
169 var $sql1 = 'sql1'; // used for casting sql1 to text for mssql
171 var $helpurl = "<a href=http://phplens.com/adodb/reference.functions.fnexecute.and.fncacheexecute.properties.html#logsql>LogSQL help</a>";
172 var $createTableSQL = false;
173 var $maxLength = 2000;
175 // Sets the tablename to be used
176 function table($newtable = false)
180 if (!empty($newtable)) $_table = $newtable;
181 if (empty($_table)) $_table = 'adodb_logsql';
185 // returns array with info to calculate CPU Load
190 cpu 524152 2662 2515228 336057010
191 cpu0 264339 1408 1257951 168025827
192 cpu1 259813 1254 1257277 168031181
195 intr 890153570 868093576 6 0 4 4 0 6 1 2 0 0 0 124 0 8098760 2 13961053 0 0 0 0 0 0 0 0 0 0 0 0 0 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
196 disk_io: (3,0):(3144904,54369,610378,3090535,50936192) (3,1):(3630212,54097,633016,3576115,50951320)
202 // Algorithm is taken from
203 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp
204 if (strncmp(PHP_OS
,'WIN',3)==0) {
205 @$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'");
206 if (!$c) return false;
208 $info[0] = $c->PercentProcessorTime
;
211 $info[3] = $c->TimeStamp_Sys100NS
;
216 // Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com)
217 $statfile = '/proc/stat';
218 if (!file_exists($statfile)) return false;
220 $fd = fopen($statfile,"r");
221 if (!$fd) return false;
223 $statinfo = explode("\n",fgets($fd, 1024));
225 foreach($statinfo as $line) {
226 $info = explode(" ",$line);
227 if($info[0]=="cpu") {
228 array_shift($info); // pop off "cpu"
229 if(!$info[0]) array_shift($info); // pop off blank space (if any)
238 /* NOT IMPLEMENTED */
243 total: used: free: shared: buffers: cached:
244 Mem: 1055289344 917299200 137990144 0 165437440 599773184
245 Swap: 2146775040 11055104 2135719936
253 Inact_dirty: 322856 kB
254 Inact_clean: 24256 kB
255 Inact_target: 168316 kB
260 SwapTotal: 2096460 kB
262 Committed_AS: 348732 kB
268 Remember that this is client load, not db server load!
273 $info = $this->_CPULoad();
274 if (!$info) return false;
276 if (empty($this->_lastLoad
)) {
278 $this->_lastLoad
= $info;
279 $info = $this->_CPULoad();
282 $last = $this->_lastLoad
;
283 $this->_lastLoad
= $info;
285 $d_user = $info[0] - $last[0];
286 $d_nice = $info[1] - $last[1];
287 $d_system = $info[2] - $last[2];
288 $d_idle = $info[3] - $last[3];
290 //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle);
292 if (strncmp(PHP_OS
,'WIN',3)==0) {
293 if ($d_idle < 1) $d_idle = 1;
294 return 100*(1-$d_user/$d_idle);
296 $total=$d_user+
$d_nice+
$d_system+
$d_idle;
297 if ($total<1) $total=1;
298 return 100*($d_user+
$d_nice+
$d_system)/$total;
302 function Tracer($sql)
304 $perf_table = adodb_perf
::table();
305 $saveE = $this->conn
->fnExecute
;
306 $this->conn
->fnExecute
= false;
308 $sqlq = $this->conn
->qstr($sql);
309 $arr = $this->conn
->GetArray(
310 "select count(*),tracer
311 from $perf_table where sql1=$sqlq
316 $s .= '<h3>Scripts Affected</h3>';
317 foreach($arr as $k) {
318 $s .= sprintf("%4d",$k[0]).' '.strip_tags($k[1]).'<br>';
321 $this->conn
->fnExecute
= $saveE;
326 Explain Plan for $sql.
327 If only a snippet of the $sql is passed in, then $partial will hold the crc32 of the
330 function Explain($sql,$partial=false)
335 function InvalidSQL($numsql = 10)
337 global $HTTP_GET_VARS;
339 if (isset($HTTP_GET_VARS['sql'])) return;
340 $s = '<h3>Invalid SQL</h3>';
341 $saveE = $this->conn
->fnExecute
;
342 $this->conn
->fnExecute
= false;
343 $perf_table = adodb_perf
::table();
344 $rs =& $this->conn
->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql);
345 $this->conn
->fnExecute
= $saveE;
347 $s .= rs2html($rs,false,false,false,false);
349 return "<p>$this->helpurl. ".$this->conn
->ErrorMsg()."</p>";
356 This script identifies the longest running SQL
358 function _SuspiciousSQL($numsql = 10)
360 global $ADODB_FETCH_MODE,$HTTP_GET_VARS;
362 $perf_table = adodb_perf
::table();
363 $saveE = $this->conn
->fnExecute
;
364 $this->conn
->fnExecute
= false;
366 if (isset($HTTP_GET_VARS['exps']) && isset($HTTP_GET_VARS['sql'])) {
367 $partial = !empty($HTTP_GET_VARS['part']);
368 echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
371 if (isset($HTTP_GET_VARS['sql'])) return;
374 $save = $ADODB_FETCH_MODE;
375 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
376 //$this->conn->debug=1;
377 $rs =& $this->conn
->SelectLimit(
378 "select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
380 where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
381 and (tracer is null or tracer not like 'ERROR:%')
383 order by 1 desc",$numsql);
384 $ADODB_FETCH_MODE = $save;
385 $this->conn
->fnExecute
= $saveE;
387 if (!$rs) return "<p>$this->helpurl. ".$this->conn
->ErrorMsg()."</p>";
388 $s = "<h3>Suspicious SQL</h3>
389 <font size=1>The following SQL have high average execution times</font><br>
390 <table border=1 bgcolor=white><tr><td><b>Avg Time</b><td><b>Count</b><td><b>SQL</b><td><b>Max</b><td><b>Min</b></tr>\n";
391 $max = $this->maxLength
;
393 $sql = $rs->fields
[1];
394 $raw = urlencode($sql);
395 if (strlen($raw)>$max-100) {
396 $sql2 = substr($sql,0,$max-500);
397 $raw = urlencode($sql2).'&part='.crc32($sql);
399 $prefix = "<a target=sql".rand()." href=\"?hidem=1&exps=1&sql=".$raw."&x#explain\">";
401 if ($this->explain
== false ||
strlen($prefix)>$max) {
402 $suffix = ' ... <i>String too long for GET parameter: '.strlen($prefix).'</i>';
405 $s .= "<tr><td>".round($rs->fields
[0],6)."<td align=right>".$rs->fields
[2]."<td><font size=-1>".$prefix.htmlspecialchars($sql).$suffix."</font>".
406 "<td>".$rs->fields
[3]."<td>".$rs->fields
[4]."</tr>";
409 return $s."</table>";
413 function CheckMemory()
419 function SuspiciousSQL($numsql=10)
421 return adodb_perf
::_SuspiciousSQL($numsql);
424 function ExpensiveSQL($numsql=10)
426 return adodb_perf
::_ExpensiveSQL($numsql);
431 This reports the percentage of load on the instance due to the most
432 expensive few SQL statements. Tuning these statements can often
433 make huge improvements in overall system performance.
435 function _ExpensiveSQL($numsql = 10)
437 global $HTTP_GET_VARS,$ADODB_FETCH_MODE;
439 $perf_table = adodb_perf
::table();
440 $saveE = $this->conn
->fnExecute
;
441 $this->conn
->fnExecute
= false;
443 if (isset($HTTP_GET_VARS['expe']) && isset($HTTP_GET_VARS['sql'])) {
444 $partial = !empty($HTTP_GET_VARS['part']);
445 echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
448 if (isset($HTTP_GET_VARS['sql'])) return;
451 $save = $ADODB_FETCH_MODE;
452 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
453 $rs =& $this->conn
->SelectLimit(
454 "select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
456 where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
457 and (tracer is null or tracer not like 'ERROR:%')
459 order by 1 desc",$numsql);
461 $this->conn
->fnExecute
= $saveE;
462 $ADODB_FETCH_MODE = $save;
463 if (!$rs) return "<p>$this->helpurl. ".$this->conn
->ErrorMsg()."</p>";
464 $s = "<h3>Expensive SQL</h3>
465 <font size=1>Tuning the following SQL will reduce the server load substantially</font><br>
466 <table border=1 bgcolor=white><tr><td><b>Load</b><td><b>Count</b><td><b>SQL</b><td><b>Max</b><td><b>Min</b></tr>\n";
467 $max = $this->maxLength
;
469 $sql = $rs->fields
[1];
470 $raw = urlencode($sql);
471 if (strlen($raw)>$max-100) {
472 $sql2 = substr($sql,0,$max-500);
473 $raw = urlencode($sql2).'&part='.crc32($sql);
475 $prefix = "<a target=sqle".rand()." href=\"?hidem=1&expe=1&sql=".$raw."&x#explain\">";
477 if($this->explain
== false ||
strlen($prefix>$max)) {
481 $s .= "<tr><td>".round($rs->fields
[0],6)."<td align=right>".$rs->fields
[2]."<td><font size=-1>".$prefix.htmlspecialchars($sql).$suffix."</font>".
482 "<td>".$rs->fields
[3]."<td>".$rs->fields
[4]."</tr>";
485 return $s."</table>";
489 Raw function to return parameter value from $settings.
491 function DBParameter($param)
493 if (empty($this->settings
[$param])) return false;
494 $sql = $this->settings
[$param][1];
495 return $this->_DBParameter($sql);
499 Raw function returning array of poll paramters
501 function &PollParameters()
503 $arr[0] = (float)$this->DBParameter('data cache hit ratio');
504 $arr[1] = (float)$this->DBParameter('data reads');
505 $arr[2] = (float)$this->DBParameter('data writes');
506 $arr[3] = (integer) $this->DBParameter('current connections');
511 Low-level Get Database Parameter
513 function _DBParameter($sql)
515 $savelog = $this->conn
->LogSQL(false);
516 if (is_array($sql)) {
517 global $ADODB_FETCH_MODE;
521 if (sizeof($sql)>2) $pos = $sql[2];
523 if (sizeof($sql)>3) $coef = $sql[3];
526 $save = $ADODB_FETCH_MODE;
527 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
528 $rs = $this->conn
->Execute($sql1);
529 $ADODB_FETCH_MODE = $save;
532 $keyf = reset($rs->fields
);
533 if (trim($keyf) == $key) {
534 $ret = $rs->fields
[$pos];
535 if ($coef) $ret *= $coef;
542 $this->conn
->LogSQL($savelog);
545 if (strncmp($sql,'=',1) == 0) {
546 $fn = substr($sql,1);
549 $sql = str_replace('$DATABASE',$this->conn
->database
,$sql);
550 $ret = $this->conn
->GetOne($sql);
551 $this->conn
->LogSQL($savelog);
558 Warn if cache ratio falls below threshold. Displayed in "Description" column.
560 function WarnCacheRatio($val)
562 if ($val < $this->warnRatio
)
563 return '<font color=red><b>Cache ratio should be at least '.$this->warnRatio
.'%</b></font>';
567 /***********************************************************************************************/
568 // HIGH LEVEL UI FUNCTIONS
569 /***********************************************************************************************/
572 function UI($pollsecs=5)
574 global $HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_POST_VARS;
576 $perf_table = adodb_perf
::table();
580 if ($conn->host
&& $conn->database
) $app .= ', db=';
581 $app .= $conn->database
;
583 if ($app) $app .= ', ';
584 $savelog = $this->conn
->LogSQL(false);
585 $info = $conn->ServerInfo();
586 if (isset($HTTP_GET_VARS['clearsql'])) {
587 $this->conn
->Execute("delete from $perf_table");
589 $this->conn
->LogSQL($savelog);
593 if (isset($HTTP_GET_VARS['sql']) && get_magic_quotes_gpc()) {
594 $_GET['sql'] = $HTTP_GET_VARS['sql'] = str_replace(array("\\'",'\"'),array("'",'"'),$HTTP_GET_VARS['sql']);
597 if (!isset($_SESSION['ADODB_PERF_SQL'])) $nsql = $_SESSION['ADODB_PERF_SQL'] = 10;
598 else $nsql = $_SESSION['ADODB_PERF_SQL'];
600 $app .= '<font size=-1>'.$info['description'].'</font>';
603 if (isset($HTTP_GET_VARS['do'])) $do = $HTTP_GET_VARS['do'];
604 else if (isset($HTTP_POST_VARS['do'])) $do = $HTTP_POST_VARS['do'];
605 else if (isset($HTTP_GET_VARS['sql'])) $do = 'viewsql';
608 if (isset($HTTP_GET_VARS['nsql'])) {
609 if ($HTTP_GET_VARS['nsql'] > 0) $nsql = $_SESSION['ADODB_PERF_SQL'] = (integer) $HTTP_GET_VARS['nsql'];
611 echo "<title>ADOdb Performance Monitor on $app</title><body bgcolor=white>";
612 if ($do == 'viewsql') $form = "<td><form># SQL:<input type=hidden value=viewsql name=do> <input type=text size=4 name=nsql value=$nsql><input type=submit value=Go></td></form>";
613 else $form = "<td> </td>";
615 $allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
617 if (empty($HTTP_GET_VARS['hidem']))
618 echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2>
619 <b><a href=http://php.weblogs.com/adodb?perf=1>ADOdb</a> Performance Monitor</b> for $app</tr><tr><td>
620 <a href=?do=stats>Performance Stats</a> <a href=?do=viewsql>View SQL</a>
621 <a href=?do=tables>View Tables</a> <a href=?do=poll>Poll Stats</a>",
622 $allowsql ?
' <a href=?do=dosql>Run SQL</a>' : '',
630 echo $this->HealthCheck();
631 $this->conn
->debug
=1;
632 echo $this->CheckMemory();
635 echo "<iframe width=720 height=80%
636 src=\"{$HTTP_SERVER_VARS['PHP_SELF']}?do=poll2&hidem=1\"></iframe>";
640 $this->Poll($pollsecs);
644 if (!$allowsql) break;
649 if (empty($HTTP_GET_VARS['hidem']))
650 echo " <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>";
651 echo($this->SuspiciousSQL($nsql));
652 echo($this->ExpensiveSQL($nsql));
653 echo($this->InvalidSQL($nsql));
656 echo $this->Tables(); break;
659 echo "<p><div align=center><font size=1>$ADODB_vers Sponsored by <a href=http://phplens.com/>phpLens</a></font></div>";
663 Runs in infinite loop, returning real-time statistics
665 function Poll($secs=5)
667 $this->conn
->fnExecute
= false;
668 //$this->conn->debug=1;
669 if ($secs <= 1) $secs = 1;
670 echo "Accumulating statistics, every $secs seconds...\n";flush();
671 $arro =& $this->PollParameters();
676 $arr =& $this->PollParameters();
678 $hits = sprintf('%2.2f',$arr[0]);
679 $reads = sprintf('%12.4f',($arr[1]-$arro[1])/$secs);
680 $writes = sprintf('%12.4f',($arr[2]-$arro[2])/$secs);
681 $sess = sprintf('%5d',$arr[3]);
683 $load = $this->CPULoad();
684 if ($load !== false) {
685 $oslabel = 'WS-CPU%';
686 $osval = sprintf(" %2.1f ",(float) $load);
691 if ($cnt %
10 == 0) echo " Time ".$oslabel." Hit% Sess Reads/s Writes/s\n";
693 echo date('H:i:s').' '.$osval."$hits $sess $reads $writes\n";
702 Returns basic health check in a command line interface
704 function HealthCheckCLI()
706 return $this->HealthCheck(true);
711 Returns basic health check as HTML
713 function HealthCheck($cli=false)
715 $saveE = $this->conn
->fnExecute
;
716 $this->conn
->fnExecute
= false;
717 if ($cli) $html = '';
718 else $html = $this->table
.'<tr><td colspan=3><h3>'.$this->conn
->databaseType
.'</h3></td></tr>'.$this->titles
;
722 foreach($this->settings
as $name => $arr) {
723 if ($arr === false) break;
725 if (!is_string($name)) {
726 if ($cli) $html .= " -- $arr -- \n";
727 else $html .= "<tr bgcolor=$this->color><td colspan=3><i>$arr</i> </td></tr>";
731 if (!is_array($arr)) break;
734 if (sizeof($arr)>2) $desc = $arr[2];
735 else $desc = ' ';
738 if ($category == 'HIDE') continue;
740 $val = $this->_DBParameter($how);
742 if ($desc && strncmp($desc,"=",1) === 0) {
743 $fn = substr($desc,1);
744 $desc = $this->$fn($val);
747 if ($val === false) {
748 $m = $this->conn
->ErrorMsg();
751 if (is_numeric($val) && $val >= 256*1024) {
752 if ($val %
(1024*1024) == 0) {
755 } else if ($val %
1024 == 0) {
759 //$val = htmlspecialchars($val);
762 if ($category != $oldc) {
764 //$bgc = ($bgc == ' bgcolor='.$this->color) ? ' bgcolor=white' : ' bgcolor='.$this->color;
766 if (strlen($desc)==0) $desc = ' ';
767 if (strlen($val)==0) $val = ' ';
769 $html .= str_replace(' ','',sprintf($this->cliFormat
,strip_tags($name),strip_tags($val),strip_tags($desc)));
772 $html .= "<tr$bgc><td>".$name.'</td><td>'.$val.'</td><td>'.$desc."</td></tr>\n";
776 if (!$cli) $html .= "</table>\n";
777 $this->conn
->fnExecute
= $saveE;
782 function Tables($orderby='1')
784 if (!$this->tablesSQL
) return false;
786 $savelog = $this->conn
->LogSQL(false);
787 $rs = $this->conn
->Execute($this->tablesSQL
.' order by '.$orderby);
788 $this->conn
->LogSQL($savelog);
789 $html = rs2html($rs,false,false,false,false);
794 function CreateLogTable()
796 if (!$this->createTableSQL
) return false;
798 $savelog = $this->conn
->LogSQL(false);
799 $ok = $this->conn
->Execute($this->createTableSQL
);
800 $this->conn
->LogSQL($savelog);
801 return ($ok) ?
true : false;
806 global $HTTP_SERVER_VARS,$HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_SESSION_VARS;
808 $HTTP_VARS = array_merge($HTTP_GET_VARS,$HTTP_POST_VARS);
810 $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
811 $sql = isset($HTTP_VARS['sql']) ?
$HTTP_VARS['sql'] : '';
813 if (isset($HTTP_SESSION_VARS['phplens_sqlrows'])) $rows = $HTTP_SESSION_VARS['phplens_sqlrows'];
816 if (isset($HTTP_VARS['SMALLER'])) {
818 if ($rows < 3) $rows = 3;
819 $HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
821 if (isset($HTTP_VARS['BIGGER'])) {
823 $HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
828 <form method
="POST" action
="<?php echo $PHP_SELF ?>">
830 <td
> Form size
: <input type
="submit" value
=" < " name
="SMALLER"><input type
="submit" value
=" > > " name
="BIGGER">
833 <input type
="submit" value
=" Run SQL Below " name
="RUN"><input type
=hidden name
=do value
=dosql
>
836 <td colspan
=2><textarea rows
=<?php
print $rows; ?
> name
="sql" cols
="80"><?php
print htmlspecialchars($sql) ?
></textarea
>
843 if (!isset($HTTP_VARS['sql'])) return;
845 $sql = $this->undomq(trim($sql));
846 if (substr($sql,strlen($sql)-1) === ';') {
848 $sqla = $this->SplitSQL($sql);
853 foreach($sqla as $sqls) {
855 if (!$sqls) continue;
858 print "<p>".htmlspecialchars($sqls)."</p>";
861 $savelog = $this->conn
->LogSQL(false);
862 $rs = $this->conn
->Execute($sqls);
863 $this->conn
->LogSQL($savelog);
864 if ($rs && is_object($rs) && !$rs->EOF
) {
866 while ($rs->NextRecordSet()) {
867 print "<table width=98% bgcolor=#C0C0FF><tr><td> </td></tr></table>";
871 $e1 = (integer) $this->conn
->ErrorNo();
872 $e2 = $this->conn
->ErrorMsg();
873 if (($e1) ||
($e2)) {
874 if (empty($e1)) $e1 = '-1'; // postgresql fix
875 print ' '.$e1.': '.$e2;
877 print "<p>No Recordset returned<br></p>";
883 function SplitSQL($sql)
885 $arr = explode(';',$sql);
891 if (get_magic_quotes_gpc()) {
893 $m = str_replace('\\\\','\\',$m);
894 $m = str_replace('\"','"',$m);
895 $m = str_replace('\\\'','\'',$m);