Ankündigung

Einklappen
Keine Ankündigung bisher.

SQL Datei mit PHP ausführen

Einklappen

Neue Werbung 2019

Einklappen
Dieses Thema ist geschlossen.
X
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • SQL Datei mit PHP ausführen

    Hallo,

    habe ein Problem, wo ich nicht weiter komme.
    Ich habe für mein Gästebuch, ein kleines Installationsscript geschrieben, es klappt auch alles außer der Teil, wo die Tabellen in der DB erstellt werden sollen.

    PHP-Code:
    /*CREATE SQL FILE*/
            
    $md5_pw md5($_POST['ebook_admin_pw']);
            require_once(
    "install_sql.php" );
            
    create_sql_file($sql'../install/install.sql');
            
            
    /*CREATE ALL DB TABLES*/
            
    mysql_queryfile_get_contents"install.sql" ), $db ) OR die(mysql_error()); 
    Wie man sieht, schreibe ich erst ein SQL File aus den Informationen der Eingabe die der User macht, und will sie dann mit einem mysql_query in der DB ausführen.
    Die erstellt SQL File sieht so aus:

    Code:
    CREATE TABLE IF NOT EXISTS `ebook_entrys` (
      `id` int(15) NOT NULL AUTO_INCREMENT,
      `author` varchar(250) NOT NULL,
      `author_website` varchar(250) NOT NULL,
      `author_place` varchar(250) NOT NULL,
      `author_ip` varchar(25) NOT NULL,
      `message` text NOT NULL,
      `date` int(15) NOT NULL,
      `allowed` smallint(1) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
    
    CREATE TABLE IF NOT EXISTS `ebook_main_config` (
      `id` int(15) NOT NULL AUTO_INCREMENT,
      `site_title` text NOT NULL,
      `admin_name` varchar(250) NOT NULL,
      `admin_pw` varchar(250) NOT NULL,
      `admin_mail` text NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    
    INSERT INTO `ebook_main_config` (`id`, `site_title`, `admin_name`, `admin_pw`, `admin_mail`) VALUES
    (1, 'test', 'admin', '46ef149805b1b370596a83886b1e010e', 'malte-kiefer@web.de');
    In dieser Datei ist auch nichts anderes drinne und sie endet auch mit einer sql Endung.
    Doch schreibt mir mein Browser folgende Fehlermeldung aus:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE IF NOT EXISTS `ebook_main_config` ( `id` int(15) NOT NULL AUTO_I' at line 13
    Wenn ich den Inhalt aber nehme und über phpMyAdmin ausführe, bekomme ich keine Fehlermeldung und er führt alles wunderbau aus.

    Könnt ihr mir vielleicht weiter helfe?
    Danke

  • #2
    mysql_query kann nur einen Befehl ausführen nicht mehrere hintereinander. Du musst die Datei einlesen und in einzelne Befehle zerlegen.

    Kommentar


    • #3
      Cross-Posting: http://selfphp.de/forum/showthread.php?t=23731

      Kommentar

      Lädt...
      X