*.sql Datei via PHP Importieren

  • *.sql Datei via PHP Importieren

    Hallo,

    ich nutze folgenden Code um eine sql file via PHP zu Importieren. Soweit lüft das auch.
    Jetzt stehe ich aber vor dem Problem den präfix noch zu ändern, von demo_ auf domain_

    Quellcode

    1. // Temporary variable, used to store current query
    2. $templine = '';
    3. // Read in entire file
    4. $lines = file($filename);
    5. // Loop through each line
    6. foreach ($lines as $line)
    7. {
    8. // Skip it if it's a comment
    9. if (substr($line, 0, 2) == '--' || $line == '')
    10. continue;
    11. // Add this line to the current segment
    12. $templine .= $line;
    13. // If it has a semicolon at the end, it's the end of the query
    14. if (substr(trim($line), -1, 1) == ';')
    15. {
    16. // Perform the query
    17. mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
    18. // Reset temp variable to empty
    19. $templine = '';
    20. }
    21. }
    Alles anzeigen

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Fragz ()