Re: Parsing CSV files into a MySQL Table
| From: | Jason Wong | Date: | Tue, 02 Nov 2004 22:12:25 +0000 |
| Subject: | Re: Parsing CSV files into a MySQL Table | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-37142@lists.php.net to get a copy of this message | ||
On Tuesday 02 November 2004 13:46, Mark Benson wrote:
> mysql_connect (localhost, foouser, foologin);
Always use check the return value of any mysql_*() function you use and make
use of mysql_error().
> $csvfile = file("http://foo.com/foolist.csv");
If you're using a newer version of PHP you can use fgetcsv() instead. Even
better, if you're able to, use MySQL's LOAD DATA.
> foreach($csvfile as $line_no => $datastring) {
As you're not using $line_no the following is better:
foreach ($csvfile as $datastring) {
> mysql_query ("INSERT INTO 'footable' (foo1, foo2, foo3, foo4, foo5, foo6,
> foo7) VALUES '$foo1', '$foo2', '$foo3', '$foo4',
> '$foo5', '$foo6',
> '$foo7')"); }
Again, use mysql_error().
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
------------------------------------------
/*
Michelle: You should be chief.
Fry: What do I need, ulcers?
*/