We are using single source with multiple database concept. I am trying to restore db(.sql file) to client database, all tables restore fine except trigger and stored procedure.
public function import_database(){
$data = $this->input->post();
if(!empty($data))
{
$config_app = array(
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => $data['cmp_db_name'],
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE
);
$this->db =$this->load->database($config_app,TRUE); // open client database connection
$filename=$_FILES["database"]["tmp_name"];
$templine = '';
$lines = file($filename);
foreach ($lines as $line)
{
if (substr($line, 0, 2) == '--' || $line == '')
continue;
$templine .= $line;
if (substr(trim($line), -1) == ';')
{
$this->db->query($templine);
$templine = '';
}
}
}
}
I got the following error:
Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER $$ CREATE DEFINER=root@localhost PROCEDURE audt_pro (IN coumn_n' at line 1 DELIMITER $$ CREATE DEFINER=root@localhost` PROCEDURE audt_pro (IN coumn_nm TEXT, IN deleted_id TEXT, IN tbl_nm VARCHAR(50)) BEGIN DECLARE qry text;