09-28-2011, 11:24 PM
(09-28-2011, 04:39 PM)Gaijin Wrote: 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)
?>
Thisis being executed if the SHOW TABLES fails for any reason, probably because of empty database or incorrect config (locahost)...PHP Code:die('SHOW TABLES ERROR')
However, you can also use mysql_list_tables(string $database [, resource $link]) instead of SHOW TABLES.
hmn, now the script is dying on the "Unknown Database!" section even when I use live, functioning database information for a forum I admin.