Here is the error I recieve:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home1/edubnini/public_html/mysql_db_size.php on line 1

Here is the output of the script:



  MySQL Database size reporter
  Version 1.0.0
  Displays all MySQL databases with their size and privileges. If configured
  per database), the INSERT and CREATE priveleges can be revoked for a
  database, to prevent growing in size. If the database drops below a set
  limit, it can unlock the database.
  This software comes without warranty. Before using it, read the license


  Author:                   Michael Boelen (michael@rootkit.nl)
  Description:              MySQL Database size reporter/checker/limiter;
  Website:                  http://www.rootkit.nl/projects/mysql_size_reporter.html
  Development start:        October 2007
  Support policy:           - No installation/usage support
			    - Features/tips can be send by the contact form
  License:		    GPL version 3 [www.gnu.org]
  Documentation:            Website and PHP script



// MySQL connection settings
// Depending if you want to check one or more databases, use the right
// username/password. If you want to check all databases, most likely
// you will need to login with the MySQL root user.

// Thresholds for the warning colors
// (red = exceeded limit, orange = warning, yellow = attention,
//  green = good, white = no usage)

// Default database limit (in megabytes)
// Note: no database locking will be performed on a generic base.

// Configure per database specific information/limits

// - Owner
// - Contact details (e-mail address)
// - Database specific limit (in megabytes). Depending on this limit, a colored bar will be drawn
//   This limit will also apply to database locking, if enabled.
// - Show tables within the application (TRUE or FALSE)
// - Allow database locking (to prevent new records being added to the database)

  No configuration needed below this point

<title>MySQL database size reporter [www.rootkit.nl]</title>
<style type="text/css">

		      font-family: verdana;
		      font-size: 11px;

		      font-family: verdana;
		      font-size: 11px;

		      background-color: navy;
		      color: white;
		      font-family: verdana;
		      font-size: 12px;
		      font-weight: bold;      



// Connect with the server
$MySQL_connect=mysql_connect($MySQL_hostname, $MySQL_username, $MySQL_password) or die ("Error: can't connect to the MySQL server");

// Get available databases
$Mdbresult = mysql_query("SHOW DATABASES");
while($Mdbs = mysql_fetch_array($Mdbresult))
    echo "<table width=\"50%\" style=\"border: 1px solid black;\" cellpadding=\"3\" cellspacing=\"0\">";
    echo "<tr><td class=\"head\" colspan=\"2\">&raquo; " . $Database . "</td></tr>";

    $result = mysql_query("SHOW TABLE STATUS");

    $size = 0;
    $table_information = "";

    while($row = mysql_fetch_array($result))
        $size += $row["Data_length"];
	// Save information about tables (with size in MB)
        $table_information .= $row["Name"] .": ". round(($row["Data_length"]/1024)/1024, 3) ." MB<br>";

    // Get size in megabytes (with 2 decimals)    
    $size = round(($size/1024)/1024, 2);

    // Set limit
    if ($threshold[$Database][dblimit]!="") { $dblimit=$threshold[rootkit][dblimit]; }
      else { $dblimit=$Limit_database_size; }
    // Percent table
    $fill = round(($size/$dblimit)*100, 0);
    echo "<tr><td width=\"30%\">Database size:</td><td>".$size." MB</td></tr>";
    echo "<tr><td>Database limit:</td><td>".$dblimit." MB</td></tr>";
    if ($threshold[$Database][admin]!="") { echo "<tr><td>Database administrator:</td><td>".$threshold[$Database][admin]."</td></tr>"; }
    if ($threshold[$Database][admin_address]!="") { echo "<tr><td>Contact details:</td><td>".$threshold[$Database][admin_address]."</td></tr>"; }

    // Assign colors    
    if ($fill>100 || $fill==100) { $fill=100; $bgcolor="red"; }
      elseif ($fill>$Limit_warning) { $bgcolor="orange"; }
      elseif ($fill>$Limit_attention) { $bgcolor="yellow"; }
      elseif ($fill==0) { $bgcolor="white"; }
      else { $bgcolor="green"; }
    // Draw table
    $table="<table width=\"100\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: 1px solid black;\"><tr>";
    if ($fill==0 || $fill>49) { $a="&nbsp;"; } else { $b="&nbsp;"; }
    $table.= "<td style=\"background-color: ".$bgcolor.";\" width=\"$fill\">".$a."</td>";
    if ($fill!=100 && $fill!=0) { $table.="<td style=\"border-left: 1px solid black;\">".$b."</td>"; }
    echo "<tr><td>Usage (".$fill."%):</td><td>$table</td></tr>";    
    if ($threshold[$Database][db_showtables]) { echo "<tr><td valign=\"top\">Table information:</td><td>".$table_information."</td></tr>"; }

    // Check permissions in database 'mysql'
    $mysqldb_query="SELECT * from `db` WHERE `Db`='".$Database."'";
    while($mysqldb_row = mysql_fetch_array($mysqldb_result))
	echo "<tr><td>Database users:</td><td>[<b>Host:</b> ".$mysqldb_row['Host']."] [<b>Db:</b> ".$mysqldb_row['Db']."] [<b>User:</b> ".$mysqldb_row['User']."]</td></tr>";
	echo "<tr><td>Database permissions:</td><td><b>Insert:</b> ";
	echo $mysqldb_row['Insert_priv'];
	echo " <b>Create:</b> ";
	echo $mysqldb_row['Create_priv'];
	echo "</td></tr>";

    if (mysql_affected_rows()==0)
        echo "<tr><td colspan=\"2\"><i>No specific database user for this database found.</i></td></tr>";

    // Lock databases (if enabled) when limit is exceeded
    if ($fill==100 && $threshold[$Database][db_allow_locking])
	$mysqldb_query="UPDATE `db` SET `Create_priv`='N', `Insert_priv`='N' WHERE `Db`='".$Database."'";

        echo "<tr><td colspan=\"2\"><b>" . mysql_affected_rows() . " database record(s) changed.</b></tr></tr>";
	// Insert your custom actions here, when the database is LOCKED
	// Examples:
	//  - Send e-mail
	//  - Create README file in html directory
	//  - Add a remark to a backend tool
     elseif ($threshold[$Database][db_allow_locking])
        // Search for locked databases, while they are below their limit (again). If we find any, we can unlock them.
	$mysqldb_query="SELECT * FROM `db` WHERE `Db`='".$Database."' AND `Create_priv`='N' AND `Insert_priv`='N'";

	// Unlock databases (if found incorrectly locked ones)
	while($mysqldb_row = mysql_fetch_array($mysqldb_result))
	    echo "<tr><td colspan=\"2\">Unlocking database (Host: ".$mysqldb_row['Host'].", Database: ".$mysqldb_row['Db'].", User: ".$mysqldb_row['User'].")... ";
	    $mysqldb_query_update="UPDATE `db` SET `Create_priv`='Y', `Insert_priv`='Y' WHERE `Db`='".$Database."'";
	    echo mysql_affected_rows()." record(s) updated.</td></tr>";
	    // Insert your custom actions here, when the database is UNLOCKED
	    // Examples:
	    //  - Send e-mail
	    //  - Create README file in html directory
	    //  - Add a remark to a backend tool

    echo "</table>\n";
    echo "<br>\n";

// Disconnect

    Before you delete the copyright line, consider:
    - Altered scripts should be made public, due the GPL license. Send me a copy
      if you adjusted the script, so the public can enjoy the new changes. Script
      donations can be done via the contact form.
    - Open Source tools/scripts development takes lots of (unpayed) time
    - If the script is used in a commercial environment, consider a donation
    - See website for more information

echo "<table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">";
echo "<tr><td style=\"border-top: 1px solid black;\">Report created by MySQL database size reporter - Copyright 2007-".date("Y")." Michael Boelen - <a href=\"http://www.rootkit.nl\">Rootkit.nl</a></td></tr>";
echo "</table>";

7 Years
Discussion Span
Last Post by ShawnCplus
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.