"MySQL is probably the most popular database being used with PHP applications. Sometimes, the databases need to be subject of maintenance tasks like optimizing heavily changed tables or repair tables that may have been affected by some kind of system malfunctioning.
MySQL provides seperate tools to perform these tasks but in the latest versions it was added the possibility request the execution of this kind of operatings via special SQL commands, but on a table by table basis.
This class provides an interface to automate the execution of these maintenance tasks on all tables of a given database.
This is a simple level of automation enables for instance the possibility to schedule the database maintenance operations by executing PHP scripts that use this class to execute the necessary maintenance tasks without human intervention."
Manuel Lemos
mysqlop.class.php
[code]
<?php
/**
* class mysql_db_optimize : Analyse and optimise mysql database
*
*
* @version 1.0.0
* @author Ben Yacoub Hatem <hatem@php.net>
* @since 26.09.2003 12:30:24
* @access public
*/
class mysql_db_optimize{
/**
*
* @access private
**/
var $_dblink;
/**
* Get accessor for $_dblink property
*
* @access public
**/
function Getdblink(){
return $this->_dblink;
} // function
/**
* Set accessor for $_dblink property
*
* @access public
**/
function Setdblink($value){
$this->_dblink = $value;
} // function
/**
*
* @access private
**/
var $_mysqlhost;
/**
* Get accessor for $_mysqlhost property
*
* @access public
**/
function Getmysqlhost(){
return $this->_mysqlhost;
} // function
/**
* Set accessor for $_mysqlhost property
*
* @access public
**/
function Setmysqlhost($value){
$this->_mysqlhost = $value;
} // function
/**
*
* @access private
**/
var $_mysql_user;
/**
* Get accessor for $_mysql_user property
*
* @access public
**/
function Getmysql_user(){
return $this->_mysql_user;
} // function
/**
* Set accessor for $_mysql_user property
*
* @access public
**/
function Setmysql_user($value){
$this->_mysql_user = $value;
} // function
/**
*
* @access private
**/
var $_mysql_password;
/**
* Get accessor for $_mysql_password property
*
* @access public
**/
function Getmysql_password(){
return $this->_mysql_password;
} // function
/**
* Set accessor for $_mysql_password property
*
* @access public
**/
function Setmysql_password($value){
$this->_mysql_password = $value;
} // function
/**
*
* @access private
**/
var $_my_database;
/**
* Get accessor for $_my_database property
*
* @access public
**/
function Getmy_database(){
return $this->_my_database;
} // function
/**
* Set accessor for $_my_database property
*
* @access public
**/
function Setmy_database($value){
$this->_my_database = $value;
} // function
/**
* Constructor
* @access protected
*/
function mysql_db_optimize(){
}
/**
* method dbconnect : connect to mysql db
*
* @access public
* @return void
**/
function dbconnect(){
/* Connexion et sélection de la base */
$this->_dblink = @mysql_connect($this->_mysql_host, $this->_mysql_user, $this->_mysql_password);
@mysql_select_db($this->_my_database);
}
/**
* method execute : execute an operation in all db table
*
* @param $operation operation to execute on DB
*
* @access public
* @return void
**/
function execute($operation = "OPTIMIZE"){
if ($operation!= "OPTIMIZE" or $operation!= "ANALYZE" or $operation!= "REPAIR") {
$operation = "OPTIMIZE";
}
$color1 = "#F57E1D";
$color2 = "#F5F6C4";
$color3 = "#FFFF40";
$db = new mysql_db_optimize;
/*
* Configurer la connexion א la base de donnיes.
*/
$db->configuredb("localhost","db_login","db_pass","ma_base");
$db->dbconnect();
/**
* Modifier la valeur de la variable operation selon :
*
* ANALYZE : analyser toutes les tables dans la base de donnיes
* OPTIMIZE : optimiser toutes les tables dans la base de donnיes
* REPAIR : rיparer toutes les tables dans la base de donnיes
*/
if(!isset($operation))
$operation = "ANALYZE";