[pmwiki-users] Problem displaying MySQL queries

Peter Bowers pbowers at pobox.com
Wed Nov 16 23:49:11 CST 2011

On Wed, Nov 16, 2011 at 10:45 PM, Nicolas Poulain
<nico.poulain at gmail.com> wrote:
> Here is the markup I use:
> # -------------------------------------
> Markup('SQL', 'fulltext', '/\(:StartSQL *(\d+):\)*(.+)\(:EndSQL
> \1:\)/sie', "SQL('\$2')");
> function SQL($SQL) {
>   global $MyPmWiki_Hostname, $MyPmWiki_Username, $MyPmWiki_Password,
> $MyPmWiki_DBName, $action;
echo "DEBUG: SQL($SQL): Entering<br>\n";
>   if (!$dbh = mysql_connect ($MyPmWiki_Hostname, $MyPmWiki_Username,
> $MyPmWiki_Password)) return "Connection Error: ".mysql_error();
echo "DEBUG: Passed connect.<br>\n";
>   if (!mysql_select_db ($MyPmWiki_DBName)) $resultStr = "Error :
> ".mysql_error();
// Oh - this may be where you have problems -- set up an if/else so
you don't do the query if you get the error
echo "DEBUG: After select_db($MyPmWiki_DBName) resultStr=$resultStr<br>\n";
>     if($result = mysql_query($SQL,$dbh)) {
echo "DEBUG: Successful query: ".count($result)."<br>\n";
>     while($row = mysql_fetch_row($result)) {
echo "DEBUG: ROW=<pre>".print_r($result, true)."</pre><br>\n";
>       foreach ($row as $field)
>       $resultStr .= "$field";
>     }
echo "DEBUG: Up until now <pre>resultStr=$resultStr</pre><br>\n";
>   }
>   else $resultStr = "SQL Error: ".mysql_error();
>   mysql_close($dbh);
echo "DEBUG: Returning <pre>resultStr=$resultStr</pre><br>\n";
>   return $resultStr;
> }

On a quick glance through I don't see anything obvious that would
cause your symptoms.  Therefore, the next step is to trace out your
script and see exactly what is happening.  I have put several echo
statements in above -- by carefully analyzing the output of what you
got as compared with what you expected to get you should be able to
figure out where the problem is.  The idea is to "create your own
debugger" -- take a look at the value of each of the key variables and
the flow of your script as it processes.

Obviously the resulting page is going to be pretty ugly and you will
get an error of headers already sent, but just ignore those -- this is
part of the *process* of debugging -- after you've solved your problem
then you'll delete (or, better yet, comment out) those echo statements
and the ugliness will disappear...

Good luck!


More information about the pmwiki-users mailing list