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

Hi All,

A while back (in 2011) Dave Edis offered the following code for a recipe in the CMSB Cookbook to test server MySQL Connection Limits.

I’ve tried to update it for msqli block and get the error:
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home3/mrqsygmy/public_html/limittest.php on line 19 Program was unable to connect to the MySQL on '162.241.253.243'. The reason given was: Warning: mysqli_get_server_info() expects parameter 1 to be mysqli, boolean given in /home3/mrqsygmy/public_html/limittest.php on line 23 Fatal error: Uncaught Error: Call to undefined function mysqli() in /home3/mrqsygmy/public_html/limittest.php:24 Stack trace: #0 {main} thrown in /home3/mrqsygmy/public_html/limittest.php on line 24

Old and new code is below.

Can anyone offer any suggestions?

Thanks,

Jerry Kornbluth

OLD CODE;

<?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 = "your host IP address";
$username = "database user name";
$password = "database password";

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

// get MySQL Version and connection limits
$query = "SELECT @@max_connections, @@max_user_connections";
$mysqlVersion = preg_replace("/[^0-9\.]/", '', mysql_get_server_info());
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
list($maxConnections, $maxUserConnections) = mysql_fetch_row($result);
if (is_resource($result)) { mysql_free_result($result); }

// show version and limits
print "MySQL Version: $mysqlVersion" ."\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> " . "\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> " . "\n";
print "<p>Done!";

?>

REVISED CODE WITH ERROR:

<?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) = mysql_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!";

?>

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

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