note 57483 added to control-structures.foreach
| From: | retulaATgmailDOTcom at osu1 dot php dot net | Date: | Wed, 05 Oct 2005 13:54:26 +0000 |
| Subject: | note 57483 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96439@lists.php.net to get a copy of this message | ||
Here is a cool script to optimize all the tables in a database! (mysql only)
<?php
// connect to the db
mysql_connect("host","username","pw");
mysql_select_db("database");
//get all tables
$alletabellen = mysql_query("SHOW TABLES");
//go trough them, save as an array
while($tabel = mysql_fetch_assoc($alletabellen)){
//go through the array ( $db => $tabelnaam )
foreach ($tabel as $db => $tabelnaam) {
//optimize every table
mysql_query("OPTIMIZE TABLE
".$tabelnaam."") or
die(mysql_error());
}
}
?>
Enjoy!
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57483
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57483&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57483&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57483&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57483&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57483&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57483&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57483&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57483&report=yes
Search -- http://master.php.net/manage/user-notes.php