|
Posted by Rik on 06/20/07 21:34
On Wed, 20 Jun 2007 22:07:07 +0200, mantrid <ian.dandav@virgin.net> wrot=
e:
>
> "Rik" <luiheidsgoeroe@hotmail.com> wrote in message
> news:op.tt6t46t6qnv3q9@metallium...
>> On Tue, 19 Jun 2007 23:30:42 +0200, Rik <luiheidsgoeroe@hotmail.com>
> wrote:
>>
>> > On Tue, 19 Jun 2007 23:03:45 +0200, mantrid <ian.dandav@virgin.net>=
>> > wrote:
>> >
>> >> Hello
>> >> Can anyone point me in the right direction for the way to read a t=
ext
>> >> file a
>> >> line at a time and separate the fields on that line and use them a=
s
>> >> data in
>> >> an INSERT to add a record to a mysql table. Then read the second l=
ine
> in
>> >> text file and repeat.
>> >>
>> >
>> > Worst case: fgets() & explode()/split(), but depending on the forma=
t
>> > fscanf() or even the great fgetcsv() can be your friends.
>>
>> Oh, and if it's possible: do not underestimate the power of LOAD DATA=
>> INFILE syntax of mysql itself. No need to fuss around in PHP if MySQL=
=
>> can
>> do it practically on it's own.
>
> Hi
> Decided to use the fgetcsv(). couldnt get LOAD DTA INFILE to work. Im
> getting close with the following script, but error message says query =
=
> failed
> as array doesnt contain data. Am I missing something obvious
>
> **********************************
> $YourFile =3D $uploadfile ;
> $handle =3D fopen($YourFile, "r");
> while (($data =3D fgetcsv($handle, 1000, ",")) !=3D=3D FALSE) {
>
> list($userid, $companyid, $aimlisted, $amount, $price, $stamp, =
> $comm,
> $datetime) =3D explode(",", $data);
Well, the power of fgetscv() is in the fact that your should not need th=
is =
explode.
Try the list() directly on the $data array. If that doesn't work, =
print_r($data) to check wether everything is OK.
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|