Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
optimize mysql through a php script
#4
(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'
Thisis being executed if the SHOW TABLES fails for any reason, probably because of empty database or incorrect config (locahost)...
However, you can also use mysql_list_tables(string $database [, resource $link]) instead of SHOW TABLES.
Reply


Messages In This Thread
RE: optimize mysql through a php script - by Gaijin - 09-28-2011, 04:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 786 07-27-2020, 11:26 PM
Last Post: tk-hassan
  Req. Upload PHP script. 3 X P L 0 I T 1 1,203 07-14-2012, 05:19 PM
Last Post: 'Snorlax
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,308 10-10-2011, 01:00 PM
Last Post: Greyersting
  Creating a simple PHP/MySQL login script ndee 16 9,496 05-14-2011, 02:18 AM
Last Post: モrainee
  Simple MySQL Tutorial Sly 4 1,099 05-14-2011, 01:53 AM
Last Post: Sly

Forum Jump:


Users browsing this thread: 1 Guest(s)