Re: Reading CSV data into a database

From: Date: Mon, 05 Feb 2001 08:38:30 +0000
Subject: Re: Reading CSV data into a database
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-5376@lists.php.net to get a copy of this message
Is this List for explaining trivial PHP-coding??? ingo baab phobo schrieb: > use the mysql functions. - see www.php.net/mysql. > if you're on windows (i assume, since you're on this list), mysql functions > are built in. > > in a nut shell : > > > $row = 1; > > $fp = fopen ("test.txt","r"); > > $con = mysql_connect(-mysql_server_ip-, -username-, -password-); > $con = mysql_select_db (-databasename-) > > > while ($data = fgetcsv ($fp, 1000, "\t")) { > > $num = count ($data); > > $row++; > > for ($c=0; $c<$num; $c++) { > > print $data[$c] . "<br>"; > > } > mysql_query("INSERT into tablename SET('blah', $data); > > > } > > fclose ($fp); > mysql_close($con); > > > > ?> > > Siggy > > ----- Original Message ----- > From: "Ben Cairns" <BenC@intasept.com> > To: <php-windows@lists.php.net> > Sent: Saturday, February 03, 2001 6:00 AM > Subject: [PHP-WIN] Reading CSV data into a database > > > I have this script: > > <? > > > > $row = 1; > > $fp = fopen ("test.txt","r"); > > while ($data = fgetcsv ($fp, 1000, "\t")) { > > $num = count ($data); > > $row++; > > for ($c=0; $c<$num; $c++) { > > print $data[$c] . "<br>"; > > } > > } > > fclose ($fp); > > > > ?> > > It reads a csv file (actually its tab seperated) into an array called > $data. > > > > When I call this in my browser, this is fine. But what I need to do is to > > put this information into a MySQL database... > > > > The file contains these fields: > > region > > event_type > > event_date > > title > > info > > times > > venue > > price > > event_id (this is auto_incrementing) > > > > How do I read this file into the database? > > > > Any help appreciated, as I have RTFM but I still no idea...... > > > > > > > > -- > > PHP Windows Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > > For additional commands, e-mail: php-windows-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.windows (#5376) next »