Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-04-2015, 07:11 PM
Falcon Capt Falcon Capt is offline
 
Join Date: May 2006
Location: U.S.
Posts: 123
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP help

I converted some MySQL code from MySQL to MySQLi and got it working (sort of), just need a little help with the PHP now...

Original code:

Code:
if ($_REQUEST['show'] == 'mysqlstats' || empty($_REQUEST['show'])) {
	print_form_header('', '');
	print_table_header('MySQL Stats &nbsp;<span class="normal">mysql_stat()</span>');
	print_description_row(si_mysqlstats());
	print_table_footer();
	}

Code:
function si_mysqlstats() {
	$s = '';
	$status = explode('  ', mysql_stat());
	while ( list($k, $v) = each($status) ) {
		$s .= $v . '<br />';
	}
	return $s;
}
====================

Code that is now working:

Code:
if ($_REQUEST['show'] == 'mysqlistats' || empty($_REQUEST['show'])) {
	print_form_header('', '');
	print_table_header('MySQLi Stats &nbsp;<span class="normal">mysqli_stat()</span>');
	print_description_row(si_mysqlistats());
	print_table_footer();
	}

Code:
function si_mysqlistats() {
$link = mysqli_connect("localhost", "dbusername", "dbpassword", "dbname");

printf(mysqli_stat($link));

mysqli_close($link);
	
	return $s;
}
But it doesn't display correctly, see attached image, it is printing above the box instead of in the box.


Also, I would like the display to be:

Uptime: 49602
Threads: 4
Questions: 850693
Slow queries: 16
Opens: 3099
Flush tables: 1
Open tables: 747
Queries per second avg: 17.150


Instead of the current:

Uptime: 49602 Threads: 4 Questions: 850693 Slow queries: 16 Opens: 3099 Flush tables: 1 Open tables: 747 Queries per second avg: 17.150


Any help would be GREATLY appreciated!
Attached Images
File Type: jpg MySQLi_stats.jpg (35.2 KB, 0 views)
Reply With Quote
  #2  
Old 07-04-2015, 07:31 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why did you change the si_mysqlstats to print out the info? You probably just needed to copy the function and change mysql_stat to mysqli_stat.
Reply With Quote
  #3  
Old 07-04-2015, 07:49 PM
Falcon Capt Falcon Capt is offline
 
Join Date: May 2006
Location: U.S.
Posts: 123
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Why did you change the si_mysqlstats to print out the info? You probably just needed to copy the function and change mysql_stat to mysqli_stat.
It wouldn't display any of the information just simply changing the function to MySQLi, with the above code was the only way I could get the info to display...
Reply With Quote
  #4  
Old 07-04-2015, 07:55 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, right, you needed the $link to call the function. So maybe this:
PHP Code:
function si_mysqlistats() {
    
$link mysqli_connect("localhost""dbusername""dbpassword""dbname");
    
$status explode('  'mysqli_stat($link));
    
mysqli_close($link);

    
$s '';
    while ( list(
$k$v) = each($status) ) {
        
$s .= $v '<br />';
    }
    return 
$s;    


And if you already have an open connection somewhere in the program, it would probably be better to change the function to take it as a parameter instead of opening another connection.
Reply With Quote
  #5  
Old 07-04-2015, 08:12 PM
Falcon Capt Falcon Capt is offline
 
Join Date: May 2006
Location: U.S.
Posts: 123
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Oh, right, you needed the $link to call the function. So maybe this:
PHP Code:
function si_mysqlistats() {
    
$link mysqli_connect("localhost""dbusername""dbpassword""dbname");
    
$status explode('  'mysqli_stat($link));
    
mysqli_close($link);

    
$s '';
    while ( list(
$k$v) = each($status) ) {
        
$s .= $v '<br />';
    }
    return 
$s;    


And if you already have an open connection somewhere in the program, it would probably be better to change the function to take it as a parameter instead of opening another connection.
You're awesome! That did it!

Many thanks!

If I already had an open connection elsewhere, what would this code look like?
Reply With Quote
  #6  
Old 07-04-2015, 08:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Falcon Capt View Post
You're awesome! That did it!

Many thanks!

If I already had an open connection elsewhere, what would this code look like?
I guess something like:
PHP Code:
function si_mysqlistats($link) { 
    
$status explode('  'mysqli_stat($link)); 

    
$s ''
    while ( list(
$k$v) = each($status) ) { 
        
$s .= $v '<br />'
    } 
    return 
$s;     

and then in the other code:
PHP Code:
    print_description_row(si_mysqlstats($link)); 

but after I posted that I realized that it looks like you're working on code from the admincp or modcp, so you might just be able to use global $db in place of $link, like

PHP Code:
function si_mysqlistats() { 
    global 
$db;
    
$status explode('  'mysqli_stat($db)); 

    
$s ''
    while ( list(
$k$v) = each($status) ) { 
        
$s .= $v '<br />'
    } 
    return 
$s;     


and you wouldn't have to change the other code.
Reply With Quote
Благодарность от:
RichieBoy67
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:53 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03979 seconds
  • Memory Usage 2,260KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (5)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (1)post_thanks_box_bit
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (1)postbit_attachment
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete