/**
* Constructor of Mysqldump. Note that in the case of an SQLite database
* connection, the filename must be in the $db parameter.
*
* @param string $db Database name
* @param string $user SQL account username
* @param string $pass SQL account password
* @param string $host SQL server to connect to
* @param string $type SQL database type
* @param array $dumpSettings SQL database settings
* @param array $pdoSettings PDO configured attributes
*/
public function __construct($db = '', $user = '', $pass = '', $host = 'localhost', $type = 'mysql', $dumpSettings = array(), $pdoSettings = array())
{
$dumpSettingsDefault = array('include-tables' => array(), 'exclude-tables' => array(), 'compress' => Mysqldump::NONE, 'no-data' => false, 'add-drop-table' => false, 'single-transaction' => true, 'lock-tables' => true, 'add-locks' => true, 'extended-insert' => true, 'disable-keys' => true, 'where' => '', 'no-create-info' => false, 'skip-triggers' => false, 'add-drop-trigger' => true, 'hex-blob' => true, 'databases' => false, 'add-drop-database' => false, 'skip-tz-utz' => false, 'no-autocommit' => true, 'default-character-set' => Mysqldump::UTF8, 'skip-comments' => false, 'skip-dump-date' => false, 'disable-foreign-keys-check' => true);
$pdoSettingsDefault = array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false);
$this->db = $db;
$this->user = $user;
$this->pass = $pass;
$colonPos = strpos($host, ':');
if (false !== $colonPos) {
$this->port = substr($host, $colonPos + 1);
$this->host = substr($host, 0, $colonPos);
} else {
$this->port = null;
$this->host = $host;
}
$this->dbType = strtolower($type);
$this->pdoSettings = self::array_replace_recursive($pdoSettingsDefault, $pdoSettings);
$this->dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);
if (!isset($this->pdoSettings[PDO::MYSQL_ATTR_INIT_COMMAND])) {
$this->pdoSettings[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->dumpSettings['default-character-set'];
}
$diff = array_diff(array_keys($this->dumpSettings), array_keys($dumpSettingsDefault));
if (count($diff) > 0) {
throw new Exception("Unexpected value in dumpSettings: (" . implode(",", $diff) . ")");
}
// Create a new compressManager to manage compressed output
$this->compressManager = CompressManagerFactory::create($this->dumpSettings['compress']);
}