PHP / MySQL Database Optimization Function
After frequent record deletion from your MySQL database tables, your tables can acquire overhead. Overhead is empty space left inside the database table due to the deletions. A great way to speed up your MySQL database, not to mention keep it compact, is to use a simple PHP function to optimize your database tables:
/* OPTIMIZE ALL TABLES */
function optimize_database($DATABASE_LINK) {
$result = mysql_query('SHOW TABLES', $DATABASE_LINK) or die('Cannot get tables');
while($table = mysql_fetch_row($result)) {
mysql_query('OPTIMIZE TABLE '.$table[0], $DATABASE_LINK) or die('Cannot optimize '.$table[0]);
}
}
I use the $DATABASE_LINK variable to keep my connection throughout my PHP script. Obviously it's not required, so you can modify the above function if you don't keep that variable.
![Interview with a Pornhub Web Developer]()
Regardless of your stance on pornography, it would be impossible to deny the massive impact the adult website industry has had on pushing the web forward. From pushing the browser's video limits to pushing ads through WebSocket so ad blockers don't detect them, you have...
![CSS @supports]()
Feature detection via JavaScript is a client side best practice and for all the right reasons, but unfortunately that same functionality hasn't been available within CSS. What we end up doing is repeating the same properties multiple times with each browser prefix. Yuck. Another thing we...
![Create a Spinning, Zooming Effect with CSS3]()
In case you weren't aware, CSS animations are awesome. They're smooth, less taxing than JavaScript, and are the future of node animation within browsers. Dojo's mobile solution, dojox.mobile, uses CSS animations instead of JavaScript to lighten the application's JavaScript footprint. One of my favorite effects...
![Sexy Opacity Animation with MooTools or jQuery]()
A big part of the sexiness that is Apple software is Apple's use of opacity. Like seemingly every other Apple user interface technique, it needs to be ported to the web (</fanboy>). I've put together an example of a sexy opacity animation technique...
Dear sir,
where we use this function?
i need help, my hosting SQl is overhead
i use this function in my function Class php file and upload it
but i see it still overhead
let me know how to use it
reply back
With a PHP script, you can have it as a stand alone (with connection info), or you can put it as part of your code, as I have.
Great script. I was looking for a way to compact a MySQL database, and this is perfect. Thanks.
This article is like my ass,
its big shit
@trimd: hei trimd, you so stupid!
if you want fast compact you can make a program with delphi or VB6 to compact it. i make a application to compact my mysql database 370MB (7years period) become 90MB. Look more carefully trimd.
make a little application to compact it, use Delphi or VB6
don’t look others samples
grow trimd !
for more explanation go to mysql site.
or dev forum for VB
try to become great programmer.
not like junior!
Thanks, for the scripts because so far I have only seen two, the one for backing up the tables and this one above. They all look to be great and I’m use them in the my project.
Thanks. I grabbed this code and created a WP plugin. Thanks again. :-)