1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <?php
class model_sqlrestore extends abstract_model{
//profil de connexion
protected $sConfig='mysqlExple';
private $tables = array();
private $options = array(
'MySQL_HOST' => '',
'MySQL_USERNAME' => '',
'MySQL_PASSWORD' => '',
'MySQL_DATABASE' => '',
'CHARSET' => 'UTF8',
'PATH' => '/',
'FTP' => false,
'FTP_HOST' => '',
'FTP_USERNAME' => '',
'FTP_PASSWORD' => '',
'FTP_PATH' => '/'
'filename' => ''
);
private $string = "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";\n\n";
private $connect;
public static function getInstance(){
return self::_getInstance(__CLASS__);
}
public function __construct($options = array()){
foreach($options as $k => $v){
$this->options[$k] = $v;
}
$this->save()
}
private function save(){
$lines = file($this->options['filename']);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
// Perform the query
$this->execute($templine) or print('Error performing query \'<strong>' . $templine . '\': <br /><br />');
// Reset temp variable to empty
$templine = '';
}
}
}
protected function query($sReq,$tParam=null){
$this->getSgbd()->getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$sth = $this->getSgbd()->getPdo()->prepare($sReq);
if(is_array($tParam)){
$sth->execute($tParam);
}else{
$sth->execute();
}
return $sth;
}
} |
Partager