Welcome to Welcome to DNF.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars

If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.

Register Today on DNForum IT'S FREE!

Results 1 to 2 of 2
  1. #1
    DNF Addict
    Mr.Domains's Avatar
    Join Date
    Sep 2004
    Location
    Geneva, Switz.
    Posts
    1,868
    Country

    Great Britain
    DNF$
    3,242
    Bank
    6,090
    Total DNF$
    9,332
    Donate  

    Importing MySQL db with un-escaped quotes?

    I am offering 1000 DNF$ to anyone who can help me solve this!

    I bought a 300 Mb database, 60K+ records, in the form of a large flattext .sql file, but when I came to import it, many of the records contain un-escaped quotes (') which messes up the SQL INSERT queries:
    INSERT INTO `articles` VALUES ('','Planning Your Wedding Is Easy','<p>Planning a wedding is one of the most nerve wracking times in any person's life...','Marriage-Wedding','Active');
    Obviously, it's not just a case of escaping every quote in the file, because the quotes between the record's fields are necessary:
    INSERT INTO `articles` VALUES ('','Planning Your Wedding Is Easy','<p>Planning a wedding is one of the most nerve wracking times in any person\'s life...','Marriage-Wedding','Active');
    ... so what do I do? You can't escape them by hand because there's 60,000+ records, so how do I get them into a database?
    Neil Hillman - Web Developer, Pixel Pusher...

  2. #2
    Web Guru

    Join Date
    Apr 2003
    Location
    Connecticut
    Posts
    208
    DNF$
    2,106
    Bank
    0
    Total DNF$
    2,106
    Donate  

    Re: Importing MySQL db with un-escaped quotes?

    If you have PHP5 & the file is writeable.. create a copy to test on, but try the following:
    PHP Code:
    <?php
        $file 
    'sqldump.sql';
        
        
    $sql file_get_contents($file);
        
        
    $sql ereg_replace("'s","\'s ",$sql);
        
    $sql ereg_replace("'t","\'s.",$sql);
        
    $sql ereg_replace("'s","\'t ",$sql);
        
    $sql ereg_replace("'t","\'t.",$sql);
        
        
    file_put_contents($file,$sql);
    ?>
    That /should/ work.


    edit--fixed a few typoes
    Last edited by dotDan; 12-16-2005 at 10:23 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Domain name forum recommended by Domaining.com