DragonPrime - LoGD Resource Community
Welcome Guest
  • Good evening, Guest.
    Please log in, or register.
  • May 19, 2013, 05:48:04 PM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1]   Go Down
  Print  
Author Topic: Checking the query content on each page?  (Read 381 times)
0 Members and 1 Guest are viewing this topic.
Srch
Captain of the Guard
***
Offline Offline

Posts: 133

Hi, I'm Ver!


View Profile
« on: July 29, 2012, 11:22:23 PM »

I know that this may cause even more of a drag on the MySQL if we were to list all of the queries.. but it would be only for testing purposes, and to see what all is being grabbed. So I was wondering, is there any way that the core has a function to grab all of the data being queried per page and displaying it in an array? Or not? I would go ahead and activate general logging.. But I do not know if I could grab the data from the log on that exact page or not. (My 'SHOW VARIABLES LIKE "general_log%"' displays that general logging is off by default.)

I could not seem to locate all of the GLOBAL information for $dbinfo either.
Logged

Afkamm
Mod God
*****
Online Online

Posts: 1563

MarcTheSlayer


View Profile WWW
« Reply #1 on: July 30, 2012, 05:57:27 AM »

You'll need to edit 1 or 2 core files to do this as there's nothing built in to allow you to see the queries.

In the file /lib/dbwrapper_mysql.php you could get the queries by adding a line or two inside the function db_query(). $dbinfo is already a variable that's available globally so you could use that.

Code:
<?php
if( $session['user']['superuser'] & SU_DEVELOPER $dbinfo['querydata'][] = $r;

return 
$r;

You could debug that data right there, but it'll mess up the page layout.

Now go to the page_footer(} function in the /lib/pageparts.php file and debug $dbinfo['querydata'] somewhere near the bottom.

Code:
<?php
debug
($dbinfo['querydata']);

 Smiley
Logged

Srch
Captain of the Guard
***
Offline Offline

Posts: 133

Hi, I'm Ver!


View Profile
« Reply #2 on: July 30, 2012, 06:14:53 AM »

Thank you Afkamm, for pointing me in the right direction however, that gives me Resource ID numbers.

Code:
array(349) {
'0' = 'Resource id #40'
'1' = 'Resource id #41'
'2' = 'Resource id #42'
'3' = 'Resource id #45'
'4' = 'Resource id #46'
'5' = 'Resource id #47'
'6' = 'Resource id #48'
'7' = 'Resource id #49'
'8' = 'Resource id #50'
'9' = 'Resource id #51'
'10' = 'Resource id #52'
'11' = 'Resource id #53'
'12' = 'Resource id #54'
'13' = 'Resource id #55'
'14' = 'Resource id #56'
'15' = 'Resource id #57'
'16' = 'Resource id #58'
'17' = 'Resource id #59'
Logged

Anharat
Captain of the Guard
***
Offline Offline

Posts: 191


View Profile WWW
« Reply #3 on: July 30, 2012, 01:23:56 PM »

If you want to get the results its db_fetch_assoc() which would need editing. Dont know what exactly you'd need to add there, but I must be similar to the thing Afkamm wrote before!
Logged

In a World of Compromise, we don't!
Afkamm
Mod God
*****
Online Online

Posts: 1563

MarcTheSlayer


View Profile WWW
« Reply #4 on: July 31, 2012, 08:56:08 AM »

Yeah, put this at the top of the db_fetch_assoc() function and see what happens. Cheesy

Code:
<?php
global $session,$dbinfo;
if( 
$session['user']['superuser'] & SU_DEVELOPER $dbinfo['querydata'][] = $r;
Logged

Srch
Captain of the Guard
***
Offline Offline

Posts: 133

Hi, I'm Ver!


View Profile
« Reply #5 on: July 31, 2012, 02:41:23 PM »

A lot happened, actually. More than was expected. It gave 1880 or so lines of data, in an array. No resource datas now. Smiley However, there are a lot of empty fields in the array.. And it is giving me more pieces of data than the page gen says. The page gen says there are about 300 queries. There could possibly be 1500 spaces of blank data (I would assume not with the massive scrolling I did.). However, I am seeing info that may come globally.. For example, I am seeing an array that has a co-owner's name and info, with his dragonpoints being displayed entirely..

In my excitement of having the info at my finger tips, I went ahead and tried these lines of code.
Code:
// $datacount = db_num_rows($dbinfo['querydata']);
// $startcount = 0;
// while ($datacount > $startcount){
// if (in_array(array('modulename'),$dbinfo['querydata'][$startcount])) $debugtheinfo = $dbinfo['querydata'][$startcount]['modulename']."<br>";
// $startcount++;
// }
//    debug($debugtheinfo);

They are commented out, I know, but this is an exact copy of my live server. Had to comment it out because it gave the following error, roughly 1000 times (literally):
PHP Warning: "in_array() expects parameter 2 to be array, null given"
in /opt/lampp/htdocs/lib/pageparts.php at 375.


Line 375 would be:
Code:
//  if (in_array(array('modulename'),$dbinfo['querydata'][$startcount])) $debugtheinfo = $dbinfo['querydata'][$startcount]['modulename']."<br>";

I do not see fault in this line, but I may be missing something.
Logged

Afkamm
Mod God
*****
Online Online

Posts: 1563

MarcTheSlayer


View Profile WWW
« Reply #6 on: July 31, 2012, 02:51:29 PM »

Code:
in_array('needle', 'haystack')

Where the haystack is an array and the needle is a value that you're searching the haystack for. Smiley
Logged

Srch
Captain of the Guard
***
Offline Offline

Posts: 133

Hi, I'm Ver!


View Profile
« Reply #7 on: July 31, 2012, 04:46:30 PM »

Code:
$datacount = db_num_rows($dbinfo['querydata']);
$startcount = 0;
while ($datacount > $startcount){
$m = "";
$s = "";
$f = "";
if ($dbinfo['querydata'][$startcount]['modulename']) $m = "Module: ".$dbinfo['querydata'][$startcount]['modulename']." | ";
if ($dbinfo['querydata'][$startcount]['setting']) $s = "setting(".$dbinfo['querydata'][$startcount]['setting'].", ".$dbinfo['querydata'][$startcount]['value'].") ";
if ($dbinfo['querydata'][$startcount]['function']) $f = "Function: ".$dbinfo['querydata'][$startcount]['function'];
debug($startcount.$m.$s.$f);
$startcount++;
}

This is a sloppier, but still works. Still shows about 6 times more functions than page gen indicates.
Logged

Boris735
Mod God
*****
Offline Offline

Posts: 532


View Profile
« Reply #8 on: July 31, 2012, 08:45:44 PM »

I note that db_fetch_assoc() may be called many times to process the results of a single query, so this disparity is not surprising.

If you want to see what the queries are, you could modify db_query() to save the query, in a manner similar to that originally suggested by Afkamm.  If you do, you should probably also modify db_query_cached() in similar fashion.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Version 1.1.2 is the current supported version and is available for download.

Support Us
$100 raised this year
Your help is greatly appreciated!
Who's Online
23 Guests, 2 Users
Aeo , Afkamm
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search