Source for file MySQLDatabaseHost.class.php
Documentation is available at MySQLDatabaseHost.class.php
if( !extension_loaded( 'mysql' ) )
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
require_once( CLASSPATH. "settings.inc.php" );
require_once( CLASSPATH. "databases/ABSTDatabaseHost.class.php" );
include_once( CLASSPATH. "databases/mysql/MySQLDatabase.class.php" );
include_once( CLASSPATH. "filesystem/Files.class.php" );
include_once( CLASSPATH. "filesystem/FilesystemToolkit.class.php" );
include_once( CLASSPATH. "communication/FTPHost.class.php" );
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (C) 2004 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* This reference of a FTP object is for the use that dumps should save on the
* server via FTP, cause of SAFE MODE restriction.
* Stores whether a persistant connection should be use.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $password*
* @return MySQLDatabaseHost
* Sets whether a persistant connection should be use.
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $boolean
* Adds a databasetable's reference to this object of a database.
* @author Daniel Plücken <daniel@debakel.net>
function addDB( &$db_obj )
parent::addDB( $db_obj );
"CREATE TABLE IF NOT EXISTS __admin_mysql_errorlogs ( "
. "id INT(10) UNSIGNED NOT NULL auto_increment, "
. "script_name VARCHAR(255) DEFAULT NULL, "
. "time_first DATETIME NOT NULL, "
. "time_last DATETIME NOT NULL, "
. "active TINYINT(1) UNSIGNED NOT NULL DEFAULT '1', "
. "mysql_errno INT(5) UNSIGNED NOT NULL DEFAULT '0', "
. ") TYPE = MyISAM;", true
* Sets the references to objects of databases to the attribute $this -> db.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $regExp Makes sure that only databases were stored, which
* names matching the given regular expression.
* @param string $regExp2 Makes sure that only tables of a Database were
* stored, which names matching the given regular
* @param boolean $resTab Cause whether the tables of the researched
* databases should be research too.
* @param boolean $resFld Cause whether the tables's fields of the
* researched tables should be research too.
$this->db[$i]->researchTables( $regExp2, $resFld );
$this->db[$t]->researchTables( $regExp2, $resFld );
* Dumps this Databasehost. If this object has stored ftp data the dump method
* "PHP" will be used and the dumps will be stored on the ftp server which is
* stated in the ftp data. Otherwise you can use two different methods to
* store the created dumps depending on the value of the constant
* "MYSQL_DUMP_KIND", which can be modified in the file "settings.inc.php".
* You can use the fast "MYSQLDUMP" method, if your hosting allows to use the
* function exec() and you have quoted the right path to mysqldump in the
* constant "PATH2MYSQLDUMP", also changeable in the file "settings.inc.php",
* or you can use the method "PHP". The method "PHP" do not need an external
* program but is slower than the method "MYSQLDUMP".
* @author Daniel Plücken <daniel@debakel.net>
* @param string $regExp Makes sure that only databases were stored,
* which names matching the given regular
* @param string $regExp2 Makes sure that only tables of a Database
* were stored, which names matching the given
* @param boolean $full_inserts
* @param boolean $drop_order
|| strpos( $target, "/" ) === 0
if ( $this->ftp->file_exists( $target ) )
$this->ftp->rename( $ftp_path, $ftp_path. "_". date( "Y-m-d_H:i" ) );
if ( !$this->ftp->file_exists( $target ) )
$this->ftp->mkdir( $ftp_path, 0777 );
for ( $i = 0; $i < count( $this->db ); $i++ )
if ( !$this->ftp->file_exists( $target. "/". $this->db[$i]->name ) )
$this->ftp->mkdir( $ftp_path. "/". $this->db[$i]->name, 0777 );
for ( $k = 0; $k < count( $this->db[$i]->dbt ); $k++ )
echo $this->db[$i]->dbt[$k]->getLastQuery(). "<br />\r\n";
$ftp_path. "/". $this->db[$i]->name. "/"
. $this->db[$i]->dbt[$k]->name. ".sql",
$this->db[$i]->dbt[$k]->getDump(
for( $i = 0; $i < count( $this->db ); $i++ )
if( !is_dir( $target. "/". $this->db[$i]->name ) )
mkdir( $target. "/". $this->db[$i]->name, 0777 );
@chmod( $target. "/". $this->db[$i]->name, 0777 );
echo "<b>Database</b> ". $this->db[$i]->name. "<br />\r\n";
for( $k = 0; $k < count( $this->db[$i]->dbt ); $k++ )
$tmp_data_order = $this->db[$i]->name. " "
. $this->db[$i]->dbt[$k]->name. " > "
. $target. "/". $this->db[$i]->name. "/"
. $this->db[$i]->dbt[$k]->name. ".sql";
. "--host=". $this->name. " "
. "--user=". $this->user. " "
. "--port=". $this->port. " "
#."--lines-terminated-by=\\r\\n "
for( $k = 0; $k < count( $this->db[$i]->dbt ); $k++ )
$target. "/". $this->db[$i]->name. "/"
. $this->db[$i]->dbt[$k]->name. ".sql"
$this->db[$i]->dbt[$k]->getDump(
echo $this->db[$i]->dbt[$k]->getLastQuery(). "<br />\r\n";
$target. "/". $this->db[$i]->name. "/"
. $this->db[$i]->dbt[$k]->name. ".sql",
* Researches a whole folder to import dumped data from it.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $source The source folder
* @param string $regExpFolder Makes sure that only folder will be
* imported, which names matching the given
* @param string $regExpFiles Makes sure that only files will be imported,
* which names matching the given regular
$source, "^ &$", $regExpFolder
for ( $i = 0; $i < count( $tmp_arr ); $i++ )
if ( $tmp_arr[$i]["is_dir"] )
for ( $k = 0; $k < count( $this->db ); $k++ )
if ( $this->db[$k]->name == $tmp_arr[$i]["name"] )
$this->db[$k]->importDump(
$source. "/". $tmp_arr[$i]["name"],
* Adds ftp data to this object. This can be useful for writing dumps if the
* sever has SAFE MODE restrictions.
* @author Daniel Plücken <daniel@debakel.net>
* @param string $password
{ $this->ftp = new FTPHost( $host, $user, $password, $port ); }
* Opens a connection to the database server.
* @author Daniel Plücken <daniel@debakel.net>
* @param boolean $boolean_persitant
function connect( $boolean_persitant = false )
* Closes the current connection to the database server.
* @author Daniel Plücken <daniel@debakel.net>
} // End of class MySQLDatabase
|