Re: Parsing CSV files into a MySQL Table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?
*/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux