RM - Source Code View

Source Code Viewer

This page lets you view source code from my server. The program uses a brute force code formatter to color code elements. NOTE: I wrote this program while trying to learn the vim text editor. This is not my usual coding style.

Use this select box to select a file.

Hide Lines Numbers

View: sql.php PDO Wrapper - Test

Demonstration of a function that wraps the PDO database.

Formatted Code

Below is the code all formatted with bright colors. The program links to files opened with include() and expands those opened with require(). Clicking on the require line should change visibility.

sql.php PDO Wrapper - Test

001 <!DOCTYPE html> 002 <html lang="en"> 003 <head> 004 <meta charset="UTF-8" /> 005 <meta name="viewport" content="width=device-width, initial-scale=1" /> 006 <meta name="Author" content="Kevin Delaney" /> 007 <meta name="keywords" content="pdo connection, php database connection" /> 008 <meta name="description" content="This is the test page for the sql.php object which I use to contain the PHP PDO Object." /> 009 <title>Test Page for sql.php</title> 010 <link rel="canonical" href="https://yintercept.com/resources/sqlTest.php" /> 011 <link rel="stylesheet" href="rm.css" type="text/css"> 012 </head> 013 <body> 014 <div class="main"> 015 <h2>sql Test Page</h2> 016 <p>People often confuse the term "object" and "class." Originally, the term "object design" simply meant grouping procedures and data into a cohesive structures called "objects." The "class" contruct was created for an implementation of Object Oriented Programming called "C for Classes" by Bjarne Stroustrup. C++ was optimized for creating GUI interfaces on desktop computers.</p> 017 <p>The World Wide Web is not a desktop computer. The rigid class structure adopted by PHP impedes development; So, I created a free form object which I placed in the sql.php file. I call this approach <a href="https://yintercept.com/resources/">The Resource Model</a>.</p> 018 <p>This is a test page for sql.php. Use the Code Viewer to see the test. The Test Results are below the dotted line.</p> 019 <hr style="border: 2px dotted #000"> 020 <h3>Test Results</h3> 021 <p>These are tests results for the free form sql object. NOTE: this object requires the <a href="https://yintercept.com/resources/msgTest.php">msg Notification Object</a>.</p> 022 <?php 023 /** 024 * sqlTest.php is a test script for the sql.php object. 025 * Yes, even though it doesn't use a rigid class structure, it is an object. 026 * This link shows the test results: 027 * @see https://yintercept.com/resources/sqlTest.php 028 * 029 * The sql.php object uses the msg.php notification object to report errors. 030 * This scription requires the msg.php object: 031 * @see https://yintercept.com/resources/msgTest.php 032 * 033 * @copyright 2015 kd 034 */ 035 include('/var/www/php/msg.php');
require('/var/www/php/sql.php');
001 <?php 002 /** 003 * The sql functions connect with the database using PDO and PDOStatement. 004 * NOTE, you will need to manually edit dbConn to configure the connections. 005 * 006 * @package ResourceModel 007 * @copyright 2002-2016 Kevin Delaney 008 * @license https://yintercept.com/resources/license.html 009 * @see https://yintercept.com/resources 010 * @see https://yintercept.com/resources/view.php?script=1 Source Code 011 * @version 0.0.10 012 * 013 * These are the primary functions: 014 * sqlValue() returns a single value from the database 015 * sqlRow() returns a single row from the database. 016 * sqlArr() returns a 2D array with full result set. 017 * sqlLoop @see https://yintercept.com/resources/view.php?script=10 018 * dbConn() holds the PDO Connect object. It has some additional functions: 019 * Call it with DB_BEGIN, DB_ROLLBACK & DB_COMMIT for transactions 020 * "+dbname" will run an 'ATTACH DATABASE' command 021 * DB_INSERT_ID will return the last insert id 022 * The function returns a PDOStatement if you want one of those. 023 * 024 */ 025 const SDB_PATH = '/var/www/db/'; // Location of my SQLite3 databases. 026 const DB_MAIN = 'main'; // name of your primary database 027 // dbConn will process these transactions 028 const DB_INSERT_ID =1; // returns last insert id 029 const DB_BEGIN = 3; // Begin a transaction 030 const DB_ROLLBACK = 4; // rollback a database transaction 031 const DB_COMMIT = 5; // commit a database transaction 032 const DB_CLOSE = 6; // closes connection, logs stats & returns dbCnt. 033 const DB_CNT = 7; // dbConn returns statement count. 034 const DB_ERRORS = 666; // dbConn returns error info. 035 // used by sqlRow() 036 const DB_CHK = 100; 037 const DB_MAX_ROWS = 2000; 038 // directives for sqlExec 039 const DB_ONE_MAX = 64; // rollback if more than one row updated 040 const DB_ROWCOUNT = 10; // return the row count 041 const DB_LAST_ID = 1; // same as DB_INSERT_ID 042 // include('/var/www/php/cnx.php'); 043 /** 044 * dbConn is a database connection factory that maintains an array of 045 * connections and returns PDOStatements to sql requests. 046 * Currently, I am hard coding the connectson in deConn. 047 * in a future release, connection information will be in an array 048 * 049 * @param string $sql is either SQL command or a short cut code. 050 * @param string $dbi identifies the database to use. 051 * @return mixed[] returns a PDOStatement for SQL command or info related to call. 052 */ 053 function dbConn($dbi,$sql) { 054 static $dbh = array(); // array holds the PDO objects. 055 static $dbCnt = 0; // counts calls to the database 056 static $dbTrace = ''; // holds a trace string. 057 /** register your conections here. The values of the array are: 058 * @param string dbnam -- give each db a unique name. Use 'main' for default. 059 * @param integer status starts as 0. Is 1 if connected and -1 if failed. 060 * @param string dsn is the Data Name Source for the connection 061 * @param string user is the database user name 062 * @param string pwd is the password. 063 */ 064 static $connArr = array( 065 DB_MAIN=>['status'=>0,'dsn'=>'sqlite:/var/www/db/main.db','user'=>'','pwd'=>''], 066 'log'=>['status'=>0,'dsn'=>'sqlite:/var/www/db/log.db','user'=>'','pwd'=>''] 067 ); 068 // I've defined four databases. ele is hosted by http://www.elephantsql.com 069 // the last database is a mistake ... used to test db failures. 070 $rv = false; 071 $dbCnt++; 072 $stmt = false; 073 try { 074 // verify dbi exists in the index. 075 if (isset($connArr[$dbi])) { 076 if ($connArr[$dbi]['status'] == -1) throw new Exception('No Database Connection.'); 077 } else { 078 throw new Exception('Connection "'.$dbi.'" does not exist.'); 079 } 080 if ($connArr[$dbi]['status']==0) { 081 // connect to the database 082 try { 083 $dbh[$dbi] = new PDO($connArr[$dbi]['dsn'],$connArr[$dbi]['user'],$connArr[$dbi]['pwd']); 084 $connArr[$dbi]['status'] = 1; 085 } catch(PDOException $e) { 086 // record error and set DB_ACTIVE to DB_NONE. 087 $connArr[$dbi]['status'] = -1; 088 // log database connection faxlure in a file 089 file_put_contents(SDB_PATH.'pdoerr.txt', $dbi.' //'.$_SERVER['REQUEST_TIME'].' '.$e->getMessage(), FILE_APPEND | LOCK_EX); 090 throw new Exception('Database connection '.$dbi.' failed.'); 091 } 092 } 093 // We can add little short cuts here. such as +str Attaches a database 094 if (substr($sql,0,1)=='+') { 095 if (substr_count($sql,' ')==0) { 096 $asql = 'ATTACH DATABASE '.$dbh[$dbi]->quote(SDB_PATH.substr($sql,1).'.db').' AS '.$dbh[$dbi]->quote(substr($sql,1)); 097 $dbh[$dbi]->exec($asql); 098 $dbTrace+='A'; 099 $rv = true; 100 } 101 } elseif (substr($sql,0,1) == '^') { 102 $rv = $dbh[$dbi]->quote(substr($sql,1)); 103 } elseif ($sql==DB_INSERT_ID) { 104 $rv = $dbh[$dbi]->lastInsertId(); 105 } elseif ($sql==DB_ERRORS) { 106 $rv = implode('|',$dbh[$dbi]->errorInfo()); 107 } elseif ($sql == DB_CNT) { 108 $rv = --$dbCnt; // return current dbCnt (minus this call) 109 } elseif ($sql==DB_CLOSE) { 110 $dbh[$dbi]=null; 111 $dbErrors=false; 112 $rv=$dbCnt; 113 // store a trace of page for later analysis. 114 // $page_id = 0; // will populate later. 115 msgLog('dbTrace',[0,$dbTrace]); 116 } elseif ($sql==DB_BEGIN) { 117 if ($dbh[$dbi]->inTransaction()) { 118 msgComment($dbi.' is already in transaction mode.'); 119 } else { 120 $dbh[$dbi]->beginTransaction(); 121 } 122 $rv = true; 123 } elseif ($sql==DB_ROLLBACK) { 124 if ($dbh[$dbi]->inTransaction()) { 125 $dbh[$dbi]->rollBack(); 126 } else { 127 msgComment('Rollback outside a transaction'); 128 } 129 $rv = true; 130 } elseif ($sql==DB_COMMIT) { 131 if ($dbh[$dbi]->inTransaction()) { 132 $dbh[$dbi]->commit(); 133 } else { 134 msgComment('Attempting to commit outside transaction.'); 135 } 136 $rv = true; 137 } else { 138 // return an unexecuted prepared statement to call procedure. 139 $dbTrace.=substr($sql,0,1); // add first letter of command to trace. 140 $rv = $dbh[$dbi]->prepare($sql); 141 } 142 } catch (Exception $e) { 143 msgError('PDO says: '.$e->getMessage()); 144 $rv = false; 145 } 146 return $rv; 147 } 148 /** 149 * sqlValue returns a single value from the database. 150 * @param string $sql is a SQL SELECT command 151 * @param array $arr holds parameters for the SQL command 152 * @return string The function returns the first column of first row of the result 153 */ 154 function sqlValue($sql,$arr=[],$dbi=DB_MAIN) { 155 $stmt = dbConn($dbi,$sql); 156 // return an array of zeros on failure. 157 $rv = ''; // returns a blank space on error 158 if (is_object($stmt)) { 159 if (!is_array($arr)) { 160 $tst = $arr; 161 // no need to get huffy is some forgot the brackets to make it an array. 162 if (is_string($tst) or is_numeric($tst)) { 163 $arr=[$tst]; 164 // msgComment('sqlValue - string to array'); 165 } else { 166 msgError('In valid parameter for sqlValue()'); 167 } 168 } 169 if ($stmt->execute($arr)) { 170 $row = $stmt->fetch(PDO::FETCH_NUM); 171 $rv = (isset($row[0]))? $row[0] :''; 172 } else { 173 msgError('sqlValue execute failed'); 174 msgComment($sql.'<br />Parameters = '.implode('|',$arr)); 175 } 176 } else { 177 // this should only happen with a bad SQL statement 178 msgError('sqlValue() call failed. call #'.dbConn(DB_MAIN,DB_CNT)); 179 msgComment($dbi.' '.$sql); 180 // msgComment('RV Datatype is '.gettype($stmt)); 181 } 182 return $rv; 183 } 184 /** sqlRow() retruns a row for a SQL command. The command buffers PDOStatement 185 * You can get multiple rows and use function in some loops 186 * Use sqlLoop for complex loops. 187 * @param string $sql is a SQL select command. If null; returns next row of last 188 * command. If $sql==DB_CHK it checks to see if their is a next row. 189 * @param array $arr holds variables for the SQL statement 190 * @param integer $fetchStyle determines the PDO fetch style 191 * @return mixed[] Function returns an array for sql calls or boolean for chk. 192 */ 193 function sqlRow($sql=null,$arr=null,$dbi=DB_MAIN,$fetchStyle=PDO::FETCH_NUM) { 194 static $stmt=null; 195 static $style = ''; 196 static $chkCnt = 0; 197 static $chkVal = false; 198 $rv = [false,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; 199 if ($sql == DB_CHK) { 200 $rv = ($chkCnt++ > DB_MAX_ROWS )? false : $chkVal; 201 } elseif ($sql == null) { 202 // get the next row from the existing counter. 203 $rv = $stmt->fetch($fetchStyle); 204 if ($rv===false) { 205 $rv = ($fetchStyle==PDO::FETCH_OBJ)? null : [false,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; 206 $chkVal = false; 207 } else { 208 $chkVal = true; 209 } 210 } else { 211 // get and execute a PDOStatement 212 $stmt = dbConn($dbi,$sql); 213 $style = $fetchStyle; 214 $chkVal=false; 215 if (gettype($stmt) == 'object') { 216 if ($stmt->execute($arr)) { 217 $rv = $stmt->fetch($fetchStyle); 218 if ($rv===false) { 219 $rv = ($fetchStyle==PDO::FETCH_OBJ)? null : [false,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; 220 } else { 221 $chkVal = true; 222 } 223 } else { 224 $stmt = null; 225 msgError('SQL execute failed'); 226 msgComment($sql); 227 msgComment('Parameters = '.implode('|',$arr)); 228 } 229 } else { 230 // this should only happen with a bad SQL statement 231 msgError('SQL call failed.'); 232 msgComment($sql); 233 msgComment('RV Datatype is '.gettype($stmt)); 234 } 235 } 236 return $rv; 237 } 238 /** 239 * sqlAll() returns the entire result set as a two dimensional array. 240 * @param string $sql is a SQL SELECT Statement 241 * @param array The $arr array holds values for for the SQL statement 242 * @param integer $fetchStyle is a PDO::FETCH style option 243 * @param array function always returns an array. 244 */ 245 function sqlAll($sql,$arr,$dbi=DB_MAIN,$fetchStyle=PDO::FETCH_NUM) { 246 $stmt = dbConn($dbi,$sql); 247 // return an array of zeros on failure. 248 $rv = array(); // returns a blank space on error 249 if (is_object($stmt)) { 250 if ($stmt->execute($arr)) { 251 // I break out of the function to avoid making an extra copy of results 252 return $stmt->fetchAll($fetchStyle); 253 } else { 254 msgError('SQL execute failed'); 255 msgComment($sql.'<br />Parameters: '.implode('|',$arr)); 256 } 257 } else { 258 // this should only happen with a bad SQL statement 259 msgError('SQL call failed.'); 260 msgComment($sql.'<br />RV Datatype is '.gettype($stmt)); 261 } 262 // successful calls return results straignt from driver. 263 return array(); // returns empty array on failure 264 } 265 /** 266 * sqlExec() execute a DML SQL command such as INSERT OR UPDATE 267 * @param string $sql is the SQL command to upddate 268 * @param array $arr contains variables for the SQL 269 * @param integer $directive determines the output of the command The default 270 is to return a row. DB_LAST_ID returns the last insert id. 271 DB_ONE_MAX rollsback transacation if it affects more than one row. 272 * @param string $successMsg is printed on cuccesful execution. 273 Program replaces %ID with insert id and %RS or %RC with row count. 274 * @param string $failureMsg is printed on failure of the statement 275 * @output db Updates the database 276 * @return either the row count or insert id based on $directive 277 */ 278 function sqlExec($sql,$arr,$dbi=DB_MAIN,$successMsg='',$failureMsg='',$directive=0) { 279 if ($directive==0) $directive = (substr($sql,0,6) == 'INSERT')? DB_INSERT_ID : DB_ROWCOUNT; 280 if ($directive == DB_ONE_MAX) dbConn($dbi,DB_BEGIN); 281 $stmt = (msgOkay())? dbConn($dbi,$sql) : 123; 282 $rv = 0; // returns rows affected. 283 if (is_object($stmt)) { 284 if ($stmt->execute($arr)) { 285 // prepare message. 286 $rv = $stmt->rowCount(); // rowcount is the default return value. 287 $rowStr = $rv.' rows'; 288 if ($directive == DB_ONE_MAX) { 289 if ($rv > 1) { 290 msgError('SQL Warning. '.$rowStr.' affected on single row query.<br />Rolling back transaction.'); 291 dbConn($dbi,DB_ROLLBACK); 292 msgComment('Rolled back: '.$sql); 293 } else { 294 dbConn($dbi,DB_COMMIT); 295 } 296 } 297 if ($rv == 0) { 298 $rowStr = 'no rows'; 299 } elseif ($rv == 1) { 300 $rowStr = '1 row'; 301 } 302 $insertId = dbConn($dbi,DB_INSERT_ID); 303 if ($successMsg != '') msgNote(str_replace(['%ID','%RS','%RC'],[$insertId,$rowStr,$rv],$successMsg)); 304 if ($directive == DB_INSERT_ID) $rv = $insertId; 305 } else { 306 msgError('SQL Exec: '.$failureMsg); 307 msgComment($sql.'<br />Parameters = '.implode('|',$arr).'<br />Error '.implode('|',$stmt->errorInfo())); 308 } 309 } elseif ($stmt== 123) { 310 // msgOkay reported an error. 311 } else { 312 // this should only happen with a bad SQL statement 313 msgError('SQL Call: '.$failureMsg); 314 msgComment($sql.'<br />'.implode(',',$arr).'<br />Return Datatype is '.gettype($stmt)); 315 msgComment('DB Error '.dbConn($dbi,DB_ERRORS)); 316 } 317 return $rv; 318 } 319 ?>
// End Require
036 037 $timeArr=array(); 038 $timeArr[]=['Finish Setup', microtime(true)]; 039 $GLOBALS['msg']['debugMode'] = true; // display the debug messages. 040 echo '<h3>sqlValue Test</h3>'; 041 echo '<p>The first test will use sqlValue to draw this sites name from the main database. I will format the link in sqLite3:</p>'; 042 // Since sqlValue outputs a string I can embed it in a string. 043 echo '<p>My Site Name is: '.sqlValue('SELECT site_nm FROM Web_Site WHERE site_id=?',[0]).'. '; 044 // In this second test. I format a URL in SQL and display it inline. 045 // I have to escape the quotes for PHP 046 $sql="SELECT '<a href=\"'||domain_nm||'\">'||subject_nm||'</a>' as 'Link' 047 FROM Web_Site WHERE site_id=?"; 048 echo 'I was born in '.sqlValue($sql,36).'. '; 049 // Notice how I forgot to put braces around 36. sqlValue fixed my mistake. 050 // I will use sqlRow() to extract a two column arrry and build my own link. 051 $sql = 'SELECT domain_nm, subject_nm FROM Web_Site WHERE site_id = ?'; 052 list($site_url, $subject_nm) = sqlRow($sql,[9]); 053 echo 'I am currently serving time in <a href="'.$site_url.'">'.$subject_nm.'</a>.</p>'; 054 echo '<p>I often make crazy typos when I am programming. I will make a bad SQL statement and use msgNote() to display the error. You should see an error message followed by debug note.</p>'; 055 $timeArr[]=['sqlValue Test', microtime(true)]; 056 sqlValue('SELECT important_info FROM Crazy_Typo WHERE id = ?',[1]); 057 msgHTML(); 058 $timeArr[]=['Typo Test [rem]', microtime(true)]; 059 // reset the the error toggle. 060 $GLOBALS['msg']['isOkay'] = true; 061 echo '<p>In the next test, I will attach the code database and see how many times people have viewed the <a href="https://yintercept.com/resources/view.php?script=3">sql Code Viewer Page</a>.'; 062 // the + call to dbConn attaches a local SQLLite3 database. 063 dbConn(DB_MAIN,'+code'); 064 echo ' It\'s been viewed '.sqlValue('SELECT hit_cnt FROM code.Code_Viewer WHERE code_id=?',[3],DB_MAIN).' times.</p>'; 065 msgHTML(); 066 $timeArr[]=['Attach DB Test', microtime(true)]; 067 echo '<h3>Test sqlAll() Against a Romote Database</h3>'.PHP_EOL; 068 echo '<p>The next code will test sqlAll(). This funnction selects an entire array. To make the test interesting, I created a remote postgres database with <a href="https://www.elephantsql.com/">elephantSQL.com</a>. This data is stored several hundred miles aways.</p>'; 069 // I registered a remode DB with elephantSQL.com which has the local name ele. 070 $arr=sqlAll('SELECT * FROM Test_Table ORDER BY test_id LIMIT 3',[],'ele'); 071 // let's make a quick table. 072 $rCnt = count($arr); 073 echo '<table style="margin: 4px auto; padding: 4px"> 074 <tr style="bottom-border: 2px solid #000"><th>test_id</th><th>test_nm</th><th>hit_cnt</th></tr>'.PHP_EOL; 075 for ($i=0; $i<$rCnt; $i++) { 076 echo '<tr><td>'.$arr[$i][0].'</td><td style="border-right: 2px solid #000; border-left: 2px solid #000">'.$arr[$i][1].'</td><td>'.$arr[$i][2].'</td></tr>'.PHP_EOL; 077 } 078 echo '</table>'; 079 echo '<h3>Updating with sqlExec()</h3>'; 080 echo '<p>Wow, that was fun. I can access data locally and across the country with the same driver. I know. In this next test, I will use sqlExec() to increment the counter in row two.</p>'; 081 // the directive tells sqlExec what to return. The default is to return rowcount 082 sqlExec('UPDATE Test_Table SET hit_cnt = hit_cnt+1 WHERE test_id=?',[2],'ele','Updated %RS on remote table.','Error updating remote table'); 083 echo '<p><b>msgNote</b>() will tell us if the operation was successful. I love msgNote. I run it after every sql statement when I am writing new code. It should say we updated one row.</p>'.PHP_EOL; 084 msgHTML(); 085 echo '<p>sqlValue() says the value of row two is now: '.sqlValue('SELECT hit_cnt FROM Test_Table WHERE test_id = ?',[2],'ele').'.</p>'.PHP_EOL; 086 $timeArr[]=['Remote Database Test', microtime(true)]; 087 echo '<p>The DB_ONE_MAX directive tells sqlExec to rullback if it updates more than one entry. I try to update three rows. It should rollback. The test should scream a warning at me, then a debug message showing my buggy script.</p>'; 088 sqlExec('UPDATE Test_Table SET hit_cnt = 1 WHERE test_id < ?',[4],'ele','Updated #RS.','multi-update',DB_ONE_MAX); 089 msgHTML(); 090 $GLOBALS['msg']['isOkay'] = true; 091 echo '<p>I will try to rollback and rollback without an active transaction. I will give a warning if the rollback fails and a debug comment if the commit fails.</p>'; 092 dbConn('ele',DB_CLOSE); // close resmote connection. 093 dbConn(DB_MAIN,DB_COMMIT); 094 dbConn(DB_MAIN,DB_ROLLBACK); 095 msgHTML(); 096 echo '<h2>dbConn() as a PDOStatement Factory</h2> 097 <p>The <b>sqlExec</b>() function is not really necessary. A more efficient approach is to draw a prepared PDOStatement directly from <b>dbConn</b>(). The following pseudo code uses two PDOStatements concurrently in a complex loop structure:</p> 098 <pre> 099 $sql = \'UPDATE Table ...\'; // some SQL Statement 100 $sql2 = \'INSERT INTO Table ... \'; // a statement for an inner loop 101 $arr = array(); // appropriate data for SQL. 102 $stmt = dbConn(\'main\',$sql); 103 $inner = dbConn(\'main\',$sql2); 104 while ($condition) { 105 // I create message for outer loop. 106 $arr = [ data for outer loop ]; 107 msgToggle($stmt->execute($arr,\'Success Message\',\'Failure Message\'); 108 while (inner condition) { 109 $innerArr = [ data for inner loop ]; 110 $inner->execute($innerArr); 111 } 112 } 113 </pre> 114 <p>I do not believe that functions are superior to objects. The problem I face is simply that database connection needs to be global; So, I encapsulate the PDO object in a function; so that I can generate PDOStatement Objects at will throughout the program.</p> 115 <h2>In Closing</h2> 116 <p>PHP closes all objects at the end of the script; However it is good practice to close connections.</p> 117 <p>I will now close the connections. This test session executed '.dbConn(DB_MAIN,DB_CLOSE).' sql commands. The next block shows script execution times. The calls to the remote server took up most of the time.'; 118 $timeArr[]=['DB_ONE_MAX & Rollback Test', microtime(true)]; 119 $cnt = count($timeArr); 120 $hold = $_SERVER["REQUEST_TIME_FLOAT"]; 121 echo '<table style="margin: 4px auto"> 122 <tr><th>Break</th><th>Script Time</th><th>Diff</th></tr>'.PHP_EOL; 123 for ($i=0;$i<$cnt;$i++) { 124 echo '<tr><td>'.$timeArr[$i][0]; 125 echo '</td><td style="left-border: 2px solid #000; border-right: 2px solid #000">'.($timeArr[$i][1] - $_SERVER["REQUEST_TIME_FLOAT"]); 126 echo '</td><td>'.(number_format($timeArr[$i][1] - $hold,7)).'</td></tr>'.PHP_EOL; 127 $hold= $timeArr[$i][1];; 128 } 129 echo '</table>'; 130 ?> 131 </div> 132 <p style="text-align: center"><a href="http://blog.yintercept.com" style="color: #ff8">blog</a> 133 ~ <a href="http://CommunityColor.com" style="color: #ff8">Community Color</a> 134 </p> 135 </body> 136 </html>

Use "view source" from your browser to grab the output. Feel free to link to this project and check out the Resource Model for information on PHP coding or my tumblr blog for picture of Arizona, Colorado or Utah.

File last modified at December 16 2020 00:48:13.. This page has been viewed 8147 Times.

Record of Revisions
RevbyDateDescription
0.3kd2016-01-13Changed default on sqlExec() to return last insert id on INSERT commands and row count on updates.
0.2kd2016-01-07Added the getDef Function to increment named sequences.

blog ~ Resource Model ~ links