Welcome Guest, Not a member yet? Register   Sign In
problem in restoring db script which backup from db_utility
#1

[eluser]Wades[/eluser]
Hi, I got a problem while restoring db from the script which created by backup function in db_utility.
mainly because of some special characters like \n \r. here is the detail:
suppose these is table called "test" :
Code:
CREATE TABLE test ( info TEXT NULL)
and init the table data with
Code:
INSERT INTO test (info) values("here is my test data\n test data again")

then I use the backup function to backup the data in this table
and got a file with following content in it.
Code:
#
# TABLE STRUCTURE FOR: test
#

DROP TABLE IF EXISTS test;

CREATE TABLE `test` (
  `info` text
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO test (info) VALUES ('here is my test data\\n test data again');

and then I want to restore the table with the data in this file, here is
my restore code:
Code:
$handle = fopen($filename, "r");    
while (!feof($handle))
{
    $tmp = fgets($handle);
    if (stripos($tmp,'#') === false)    // strip rows which begin with #
        $contents .= $tmp;
}
fclose($handle);

$rows = explode(";\n",$contents);

foreach ($rows as $r)
{
    $r = str_replace("\n",'',$r);
    if (!empty($r))
    {
        $this->db->query($r);
    }
}

however, when I check the data in this table,
the data becomes "here is my test data\n test data again",
the special character '\n' becomes string "\n",
that is to say that it doesn't restore the special character "\n" to what it should be,
but as strng "\n" instead. this is the problem I got.

is anyone can help?
many thanks
#2

[eluser]Sam Dark[/eluser]
Confirmed.
#3

[eluser]GSV Sleeper Service[/eluser]
why not just use LOAD DATA INFILE? it'll be a lot faster - http://dev.mysql.com/doc/refman/5.0/en/load-data.html
#4

[eluser]Wades[/eluser]
thanks GSV, but as I know, LOAD DATA INFILE is mainly used to load data into a table from a file.
but as I mentioned, the file I got from the backup function is a script with both data structure
and data, so I think this may not help here. Is anyone ever met this problem before?
#5

[eluser]Sam Dark[/eluser]
Reported it:
http://codeigniter.com/bug_tracker/bug/4536/




Theme © iAndrew 2016 - Forum software by © MyBB