note 74063 deleted from function.mysql-query by cece

From: Date: Thu, 22 Mar 2007 15:11:42 +0000
Subject: note 74063 deleted from function.mysql-query by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124718@lists.php.net to get a copy of this message
Note Submitter: Jacco <info @ netsilik *** nl> Reason: bad code ---- A function I've been using for ages now It duplicates the results as returned by your commandline mysql client. I myself use it a lot during development and debugging. Havefun with it. <?php // This function dumps the result of a MySQL query to std-out in a hmtl-table // // syntaxis: dump_mysql_results( MySQL_QUERY [, ECHO_QUERY_FLAG]); // where: MySQL_QUERY is the MySQL query to dump the results of // and // ECHO_QUERY_FLAG is an optional flag: // false: (default) do not echo the query itself // true : do echo the query function dump_mysql_results($query, $dumpQuery = false) { if ($dumpQuery) { echo "<div class=\"debug\">".$query."</div>"; } $results = mysql_query($query); if ($results && strlen(mysql_error()) == 0) { if (gettype($results) == 'boolean') { echo "<div class=\"debug\">\n\t<span style=\"font-weight: bold;\">Query OK, ".mysql_affected_rows()." rows affected</span><br/>\n<br/>\n</div>\n"; } else { // $results holds a link identifier if (mysql_num_rows($results) > 0) { echo "<table class=\"debug\">\n"; $headerRow = treu; while ($record = mysql_fetch_row($results)) { if ($headerRow) { echo "\t<tr class=\"debug\">\n"; for ($n = 0; $n < count($record); $n++) { echo "\t\t<th class=\"debug\">"; echo mysql_field_name($results, $n); echo "</th>\n"; } echo "\t</tr>\n"; $headerRow = false; } echo "\t<tr class=\"debug\">\n"; for ($n = 0; $n < count($record); $n++) { echo "\t\t<td class=\"debug\" valign=\"top\">"; if (is_null($record[$n])) { echo 'NULL'; } elseif($record[$n] == '') { echo '&nbsp;'; } else{ echo $record[$n]; } echo "</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; if (mysql_num_rows($results) > 1) { echo "<div class=\"debug\">\n\t<span style=\"font-weight: bold;\">".mysql_num_rows($results)."</span> rows in set<br/>\n<br/>\n</div>\n"; } else { echo "<div class=\"debug\">\n\t<span style=\"font-weight: bold;\">".mysql_num_rows($results)."</span> row in set<br/>\n<br/>\n</div>\n"; } } else { echo "<div class=\"debug\">\n\t<span style=\"font-weight: bold;\">empty set</span><br/>\n<br/>\n</div>\n"; } } } else { if (!$dumpQuery) { echo "<div class=\"debug\">".$query."</div>\n"; } echo "<div class=\"debug\">\n\t<br/>\n\t<span style=\"font-weight: bold;\">".mysql_error()."</span><br/>\n<br/>\n</div>\n"; } } ?>

« previous php.notes (#124718) next »