Recent Topics

1 Jun 30, 2005 01:18    

Here is a code I whipped together for checking, repairing and optimizing your b2evo blog's database. It also empties the hit log. I know the code is sloppy, but I am not very good php coder. Save the code to whatever php filename you want and place it anywhere on you blogs server. Just be sure to enter your mysql login details, etc. This code works well when run by cron every week or so. I also use this code to combat spam referral links.

<?php
// Connecting, selecting database
$link = mysql_connect('HOST', 'DATABASE NAME', 'PASSWORD')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('DATABASE NAME') or die('Could not select database');

// Performing SQL query
$query = 'CHECK TABLE `evo_antispam`, `evo_blogs`, `evo_blogusers`, `evo_categories`, `evo_comments`, `evo_groups`, `evo_hitlog`, `evo_locales`, `evo_postcats`, `evo_posts`, `evo_settings`, `evo_users`';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Performing SQL query
$query = 'REPAIR TABLE `evo_antispam`, `evo_blogs`, `evo_blogusers`, `evo_categories`, `evo_comments`, `evo_groups`, `evo_hitlog`, `evo_locales`, `evo_postcats`, `evo_posts`, `evo_settings`, `evo_users`';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Performing SQL query
$query = 'OPTIMIZE TABLE `evo_antispam`, `evo_blogs`, `evo_blogusers`, `evo_categories`, `evo_comments`, `evo_groups`, `evo_hitlog`, `evo_locales`, `evo_postcats`, `evo_posts`, `evo_settings`, `evo_users`';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Performing SQL query
$query = 'ANALYZE TABLE `evo_antispam`, `evo_blogs`, `evo_blogusers`, `evo_categories`, `evo_comments`, `evo_groups`, `evo_hitlog`, `evo_locales`, `evo_postcats`, `evo_posts`, `evo_settings`, `evo_users`';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Performing SQL query
$query = 'TRUNCATE `evo_hitlog`';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Closing connection
mysql_close($link);
?>


Form is loading...