Jump to content

Recommended Posts

You could create an additional function, or preferably a class. But if you're looking for simplicity, although I wouldn't necessary suggest it, you could just do something like this:

 

function run_mysql_query($query)
{
echo "Query: " . $query;
mysql_query($query);
}

run_mysql_query("SELECT * FROM `sometable` WHERE something='value'");

 

As I previously stated it would be better to create class because you would have much more control and less limitation.

 

Edit: Just read that you want to do it all the bottom, again you should probably use a class.. But if you want to do it the easiest (not the best) way you could do something like:

 

function run_mysql_query($query, &$querylist)
{
$querylist .= "Query: $query\n";
mysql_query($query);
}

run_mysql_query("SELECT * FROM `sometable` WHERE something='value'", $querylist);
run_mysql_query("SELECT * FROM `sometable` WHERE something='value'", $querylist);
run_mysql_query("SELECT * FROM `sometable` WHERE something='value'", $querylist);

echo $querylist;

Link to comment
https://forums.phpfreaks.com/topic/175074-how-do-i-show/#findComment-922698
Share on other sites

Are you trying to debug a script by viewing all the actual queries or display the amount of total queries ran on that page?

 

Like the footer of www.phpfreaks.com

Page created in 0.026 seconds with 7 queries.

 

I bought LivinAvatars script for 29.99$, and Im integrating with my IPB !.3.. and i just want to puti a function in index.php to show all the queries so i can get it workin better.. lol

Link to comment
https://forums.phpfreaks.com/topic/175074-how-do-i-show/#findComment-922705
Share on other sites

I'd use mysqli and extend the class. Setup a new method overloading the query method, and each time you run the query save the query string to an array. Create another that returns the array.

 

Quick example (untested):

class MySQLiX extends mysqli {
   private static $queries = array();
   function query($query) {
      self::$queries[] = $query;
      return parent::query($query);
   }
   function getQueries( ) {
      return self::$queries;
   }
}
// use:
$db = new MySQLiX('host','user', 'pass', 'world'); 
$db->query('SELECT * FROM table WHERE 1');
$db->query("DELETE FROM table WHERE col = 'val'");
print_r($db->getQueries());

 

Link to comment
https://forums.phpfreaks.com/topic/175074-how-do-i-show/#findComment-922708
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.