note 46461 deleted from function.mysql-query by philip

From: Date: Wed, 06 Apr 2005 18:00:10 +0000
Subject: note 46461 deleted from function.mysql-query by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-87600@lists.php.net to get a copy of this message
Note Submitter: Webdesign illiterate, mau at gmx dot at ---- Something for beginners. If you cannot upload a csv in mysql by using load data (local), you can use the following php-script instead. <?php $server = "localhost"; $user = "root"; $pass = ""; $database = "????"; $table = "????"; $row = 1; $handle = fopen ("lexikon.csv","r"); $verbindung = @mysql_connect($server, $user, $pass)or die ("Konnte Verbindung zur Datenbank nicht herstellen!"); mysql_select_db($database, $verbindung)or die ("SQL-FEhler: ". mysql_error()); while ( ($data = fgetcsv ($handle, 10000, ";")) !== FALSE ) { $num = count ($data); $row++; $sql ="INSERT INTO $table VALUES ('','$data[0]','$data[1]','$data[2]','')"; mysql_query($sql); } mysql_close($verbindung); fclose ($handle); ?> It is not elegant, but it works. As you might see I had a csv with 3 fields and uploaded it into a database with 5 fields, whereas the first was an ID auto_increment column (I uploaded blanks) and the fiths was a timestamp column (I didn't need any information in here). Good luck! Michi www.knauserer.com

« previous php.notes (#87600) next »