testing server MySQL Connection Limits

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 19, 2019   (RSS)

By Steve99 - July 19, 2019

Hi Jerry,

A couple small tweaks and you're there! Just update "mysql_fetch_row" to "mysqli_fetch_row". Also there was a double semi colon on the set password string line. 

<?php
//
print "<h1>MySQL Connection Limit Test</h1>\n";

// display errors
error_reporting(E_ALL); // display all errors
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
ini_set('html_errors', '0'); // don't output html links in error messages

// mysql info
$hostname = "localhost";
$username = "database user name";
$password = "database password";
$database_name = "database_name";

// connect
$DBH = @mysqli_connect($hostname, $username, $password, $database_name);
if (!$DBH) { print "Program was unable to connect to the MySQL on '$hostname'.\nThe reason given was: " . htmlspecialchars(mysqli_error()); }

// get MySQL Version and connection limits
$query = "SELECT @@max_connections, @@max_user_connections";
$mysqlVersion = preg_replace("/[^0-9\.]/", '', mysqli_get_server_info($DBH));
$result = mysqli()->query($query) or die("MySQL Error: ". htmlspecialchars(mysqil_error()) . "\n");
list($maxConnections, $maxUserConnections) = mysqli_fetch_row($result);
if (is_resource($result)) { mysqli_free_result($result); }

// show version and limits
print "MySQL Version: $mysqlVersion" ."<br />\n";
print "MySQL Max Connections: $maxConnections <a href='http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_connections'> (max_connections documentation)</a> " . "<br />\n";
print "MySQL Max User Connections: $maxUserConnections <a href='http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_user_connections'> (max_user_connections documentation)</a> " . "<br />\n";
print "<p>Done!";

?>

Cheers,
Steve

By gkornbluth - July 19, 2019

Thanks Steve,

I'll update the recipe.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php