note 46461 added to function.mysql-query
| From: | Webdesignilliterate at osu1 dot php dot net | Date: | Tue, 12 Oct 2004 14:02:49 +0000 |
| Subject: | note 46461 added to function.mysql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78415@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.mysql-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46461
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46461&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46461&report=yes
Search -- http://master.php.net/manage/user-notes.php