Hi All,
I’ve db backup.sql. I want to restore. That’s my code
$model=new Attach;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Attach']))
{
$model->attributes=$_POST['Attach'];
$inc = CUploadedFile::getInstance($model,'path');
$model->path = $inc;
if ($model->validate())
{
$fileold=Attach::model()->findAll();
if(count($fileold)>0){
$file=$fileold[0]->path;
if(isset($file))
{
if(file_exists($file))
{
unlink($file);
}
}
}
if(isset($inc->name))
{
$pic_name = 'fileattach/' . rand(2, 9999) . $inc->getName();
$inc->saveAs($pic_name);
$model->path = $pic_name;
}
if($model->save()){
$file=$model->path;
$message = 'OK. Done';
$sqlFile = $file;
if ( isset($file))
{
$sqlFile = $file;
}
if ( file_exists($sqlFile))
{
$sqlArray = file_get_contents($sqlFile);
$cmd = Yii::app()->db->createCommand($sqlArray);
try {
$cmd->execute();
}
catch(CDbException $e)
{
$message = $e->getMessage();
}
$this->render('update',array('error'=>$message));
}
};
}
}
$type=0;
$this->render('create',array(
'model'=>$model,'type'=>$type
));
Filesize is 286kb and 16 talbes. But, then restore my database have 3 or 4 tables. When I copy code in backup.sql and patse in phpmyadmin, it’s ok. Please help me, thank all