How optimize all tables using php script

Optimizing tables is very necessary for database. That will improve the your website performance.  Optimize command is helpful to manage database files in right manner. This command will optimize the size of file size of database files.

How optimize all tables using  php script

How optimize all tables using  php script
How optimize all tables using php script

If you want to optimize the all tables of database then use following script.


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
$dbconnect = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$dbconnect) {
 die('Could not connect: ' . mysql_error());
}
echo 'Connected to database successfully';

mysql_select_db('YOUR_DATABASE',$dbconnect);

dbConnect();
$alltables = mysql_query("SHOW TABLES");

while ($table = mysql_fetch_assoc($alltables))
{
 foreach ($table as $db => $tablename)
 {
 mysql_query("OPTIMIZE TABLE '".$tablename."'")
 or die(mysql_error());
 }
}
echo 'All tables optimized successfully';

mysql_close($dbconnect);
?>

The MySQL Optimize Table command will effectively de-fragment a mysql table and is very useful for tables which are frequently updated and/or deleted.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.