(09-28-2011, 12:08 AM)andrewjs18 Wrote: thanks for the script. note that in case anyone else wants to use this, they'll need to fix "locahost" in your original code to read "localhost".
if the script is showing this, and only this, on the screen (SHOW TABLES ERROR), does that mean it failed or did it run successfully?
Yeah, sorry about the typo my keyboard is finished, it should say localhost.
And I forgot to select the database, here is the full (should) working script
PHP Code:
<?php
if(!$con = mysql_connect('locahost', 'user', 'pass'))
{
die('Cannot connect!');
}
elseif(!$sel = mysql_select_db("database_name", $con))
{
die("Unknown Database!");
}
$tables = mysql_query('SHOW TABLES', $con) or die('SHOW TABLES ERROR');
while($table = mysql_fetch_row($tables))
{
mysql_query("OPTIMIZE TABLE {$table[0]}") or die(mysql_error());
}
mysql_close($con)
?>
PHP Code:
die('SHOW TABLES ERROR')
However, you can also use mysql_list_tables(string $database [, resource $link]) instead of SHOW TABLES.