sql query per php read in from file => error (correct syntax tough)

Discussion in 'PHP' started by donmiguelelunico, Jul 29, 2008.

  1. #1
    Hello guys

    I'm startled.

    I have sql code in a file, exported from phpMyAdmin. I read the text from this file in php in order to execute it, but isn't executed and says: "error near ' "
    When typing in the code in the php 1 to 1, it works, when copying the code in phpMyAdmin it works ... and it is not too long, i tried short expamples... I don't get where the problem could be, does anybody know this problem, have a hint respectively????

    Thanks for any motivation ;)
     
    donmiguelelunico, Jul 29, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Can you post the code?
     
    jestep, Jul 29, 2008 IP
  3. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Without seeing the code is difficult to tell but maybe try replacing " for ' or vice versa ...
     
    mallorcahp, Jul 29, 2008 IP
  4. donmiguelelunico

    donmiguelelunico Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok. when i wrote this i didn't have the code... but here it is (sorry, that i'm only responding now. i tought i had subscribed to this thread...but i have not.)

    i repeat: if i type the sql query exactly the same by hand, it works...

                    $sqlbuffer = Array();
                    $newsqlbuffer = Array();
                    $handle = @fopen("installation/tables.sql", "r");
                    if ($handle) {
                        while (!feof($handle)) {
                            $buffer[] = fgets($handle, 4096);
                        }
                        fclose($handle);
                    }
    
                    foreach ($buffer as $line){
                            if ( preg_match("/^\\s*(insert|create) /i",$line) ) {
                                    $newline = ereg_replace('(.+)(#PFIX#)(.+)', '\\1'.$my_db['prefix'].'\\3', $line);
                            }else{
                                    $newline = $line;
                            }
                            $newline = str_replace("\r\n", " ", $newline);
                            $newline = str_replace("\r", " ", $newline);
    
                            $newsqlbuffer[] = $newline;
                    }
                            
                    foreach ($newsqlbuffer as $line)
                            $sqlquery .= $line;
    
                    $dbinstance = new bDb();
                    $dbinstance->query($sqlquery);
    
    PHP:
    in the file tables.sql is f.ex. this:

    
    -- settings
    
    
    CREATE TABLE IF NOT EXISTS `#PFIX#_settings` (
      `setting` tinytext collate utf8_unicode_ci NOT NULL,
      `value` tinytext collate utf8_unicode_ci NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    
    
    INSERT INTO `#PFIX#_settings` (`setting`, `value`) VALUES
    ('lang', 'de'),
    ('admins', '1:'),
    ('email', ''),
    ('formlines', '12'),
    ('style', 'zock_standard'),
    ('name', 'Zock!'),
    ('description', 'The Betting Office'),
    ('account_type', 'Account'),
    ('account_details', 'xx-xxx-xxx.xx'),
    ('account_holder', 'My Name\r\nMy Street\r\nMy ZIP-Code and Town\r\nFuther Info'),
    ('notify_newaccount', 'true'),
    ('functionalSMTP', 'false'),
    ('site_url', ''),
    ('notify_participate', 'true'),
    ('notify_withdraw', 'true'),
    ('notification_system', 'internal');
    
    
    
    Code (markup):
     
    donmiguelelunico, Jul 30, 2008 IP