Jump to content

How do I show


Gayner

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.