Welcome Guest, Not a member yet? Register   Sign In
dbutil->backup newline problem (\n)
#1

[eluser]dootzky[/eluser]
Hi guys,

I've used database utility, and I'm using it for my users to quickly download and backup the entire MySQL database. And it works great.

But now I have a problem - in my CMS, I have, for example, "Webpages" control, where users can edit their own webpages, in properly implemented FCK editor. That works great, everything is by the book, etc.

And now, the problem - when ever I backup my database with dbutil class, I can import that database on my local Linux development server, but, FCK texts are getting bunch of "\n" characters all over the place, and it messes up everything in my CMS that uses FCK for editing (Webpages, Email Templates, etc.)

here's my code, it's rather straightforward and simple:

Code:
$folder = 'db_backup/';

        // Load the DB utility class
        $this->load->dbutil();
        
        $prefs = array('newline' => "\n" ); // I've tried everything here: \r, \r\n, \n, even blank - still no luck!

        // Backup your entire database and assign it to a variable
        $backup =& $this->dbutil->backup($prefs);
        
        // Load the file helper and write the file to your server
        $this->load->helper('file');
        $file_name = 'database-backup-'. date("Y-m-d-H:i") .'h.gz';
        write_file($this->config->item('assets_path') . $folder . $file_name, $backup);
        
        // Load the download helper and send the file to your desktop
        $this->load->helper('download');
        force_download($file_name, $backup);

I think that's pretty simple, right? :|
Oh, yes, one more thing that could be helpfull for you to know - when I export the database in the old, classic way from live server, from CPanel->phpMyAdmin->Export, and then I import that file on my server - it works flawlessly. Of course.

The only problem here in my thread is that I'm getting "\n" overhead, and I don't think that dbutil class should insert newline characters in SQL VALUES, but only in SQL commands... ?

Can anyone tell me where I'm mistaken? Or at least point me to some reading materials? (I've already read: http://ellislab.com/codeigniter/user-gui...ities.html , thanks Smile )

Thanks for your time and effort,
dootzky

p.s. please see attachment picture for more graphical explanation...
#2

[eluser]TheFuzzy0ne[/eluser]
I would suggest you try using the constant PHP_EOL instead - see if that makes a difference.
#3

[eluser]dootzky[/eluser]
Hi,

thanks for your reply, but it didn't solve the problem.
Everything is still the same.

I think the problem is not at all in the new line character format, the problem is that it puts a "newline character" (which ever that may be), in wrong places.

The dbutil should never place aditional newline characters in table CONTENT, right?

Is there something else that I could do here?

Thanks again for your time and help,
regards,
dootzky
#4

[eluser]TheFuzzy0ne[/eluser]
Sorry, I'm really confused. Where does FCKEditor come into this again? I don't understand why your code uses force_download, but you are displaying the problem via FCKEditor.
#5

[eluser]dootzky[/eluser]
Hi again,

I'm not sure what's confusing you, but please allow me to give you more code examples, that should clear things right up:

this is HTML code from my source-view in Firefox, or from "Source View" in FCK (in my CMS editing..)
Code:
<div class="home_promo_bottom_cnt" style="margin-right: 10px;">
<div class="home_promo_bottom_img"><a style="overflow: hidden; display: block; width: 100px; height: 76px;" href="webpage/17"><img alt="" src="/public/fck_files/image/automat za tocenje (DUPLEX).JPG" /></a></div>
<div class="home_promo_bottom_title"><b><a href="webpage/17">Autogasne stanice</a></b></div>
<div class="home_promo_bottom_desc">Postrojenje propan-butan gasa (TNG-a) je predviđeno za punjenje rezervoara motornih vozila...</div>

everything is good and clear here, right? cool. this is exactly how it's saved in my live-server database, and everything is great. yay.


Now, here is where the problem arises:
1) I export the entire MySQL database using the code given above, with DBUTIL class
2) I save that exported file on my desktop, and I do IMPORT on my local database
3) and this is what I get - corrupted data in every database field which was edited with FCK

here's a code example of corrupted data, exported with DBUTIL class:
Code:
INSERT INTO scms_webpages (id, title, subtitle, body, ordering, active, title_eng, title_rus, title_ukr, subtitle_eng, subtitle_rus, subtitle_ukr, body_eng, body_rus, body_ukr)

VALUES (10, 'Pocetna strana items', '', '<div style=\"margin-right: 10px;\" class=\"home_promo_bottom_cnt\">\\n<div class=\"home_promo_bottom_img\"><a ><img  /></a></div>\\n<div class=\"home_promo_bottom_title\"><b><a >Autogasne stanice</a></b></div>\\n<div class=\"home_promo_bottom_desc\">Postrojenje propan-butan gasa (TNG-a) je predviÄ‘eno za punjenje rezervoara motornih vozila...</div>\\n<div class=\"home_promo_bottom_dalje\"><a >detaljnije</a></div>\\n</div>\\n<div class=\"home_promo_bottom_cnt\">\\n<div class=\"home_promo_bottom_img\"><a ><img  /></a></div>\\n<div class=\"home_promo_bottom_title\"><b><a >Merno regulacione stanice</a></b></div>\\n<div class=\"home_promo_bottom_desc\">GasTeh izvodi kompletnu gasifikaciju industrijskih objekata i postrojenja na prirodni gas...</div>\\n<div class=\"home_promo_bottom_dalje\"><a >detaljnije</a></div>\\n</div>\\n

please notice bunch of "\\n" characters, which DOESN'T EXISTS in live server database!!

so the conclusion is - on live DB - everything is great
- once I do DBUTIL export, and then I look into the exported file - I notice there are bunch of "\\n" characters which are NOT supposed to be there, at all. they don't even exists in the real DB on live server.

do you see the problem now?

DBUTIL class is adding \\n characters without any reason, and as far as I can tell - it's adding those characters only in DB fields which were edited by FCK editor.

do you think that this is FCK issue?
should I perhaps report a bug on FCK development site?

again, thanks for your time and effort.
I hope we'll get to the bottom of this.

best regards,
dootzky
#6

[eluser]TheFuzzy0ne[/eluser]
Sorry for the delay in my reply. I've had some serious PC/server/network issues, and spent the last three days trying to resolve them...

Can you confirm that when you backup the database via the normal method (be it PHPMyAdmin, or over the CLI), the you don't get the same problem?

Those \\ns appear within the text (not just at the end), and therefore must be in the database like it, so it's probably an issue with FCKEditor.
#7

[eluser]TheFuzzy0ne[/eluser]
OK, I think I might have inadvertently stumbled across the solution to your problem (or rather part of it).

Code:
$str = "this\nis\na\ntest";

echo mysql_real_escape_string($str);
# Output: this\nis\na\ntest

echo mysql_real_escape_string(mysql_real_escape_string($str));
# Output: this\\nis\\na\\ntest

It would appear that your text is being escaped twice.
#8

[eluser]dootzky[/eluser]
Hi Fuzzy dude!

Thanks for replying and not forgetting me. Smile And don't worry about the long wait, you don't have an "obligation" to help me, it's just your good will and helping spirit, so I appreciate that. Really.

Alright, so, basically - it's either that FCK is causing this weird bug, but I think then you would be familiar with this bug much better, because other people would complain too, right? Almost everybody is using FCK these days for rich text formating in their CMS. Tongue

And if FCK is not to blame, then I gotta check out this other thing you found - double "mysql_real_escape_string" command.
I gotta dig deep in the code now, because I must check out entire dbutil lib now.

I'll get back to you soon with results, hopefully with a solution too. Wink

Thanks again for your time and effort mate.
cheers,
dootzky




Theme © iAndrew 2016 - Forum software by © MyBB