Parsing Tab Delimited file
Parsing Tab Delimited file
am 24.10.2010 20:46:21 von Ethan Rosenberg
Dear list -
Thanks for all your help.
I have a tab delimited file which I wish to import into a data
base. In MySQL I can use the LOAD DATA command. As far as I know,
that command cannot be used in PHP as a mysqli_query. As I
understand, I have to parse the file and use the INSERT command.
How do I do it? Code samples, please.
Thanks.
Ethan
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Parsing Tab Delimited file
am 24.10.2010 20:54:39 von Jason Pruim
On Oct 24, 2010, at 2:46 PM, Ethan Rosenberg wrote:
> Dear list -
>
> Thanks for all your help.
>
> I have a tab delimited file which I wish to import into a data
> base. In MySQL I can use the LOAD DATA command. As far as I know,
> that command cannot be used in PHP as a mysqli_query. As I
> understand, I have to parse the file and use the INSERT command.
>
> How do I do it? Code samples, please.
>
> Thanks.
http://tinyurl.com/2fnm48f
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Parsing Tab Delimited file
am 24.10.2010 20:56:45 von andresmontanez
Hi Ethan,
fist you need to read the file, you could use the file() function
which reads the file as an array, being each line an element;
the you have to navigate the array and exploding the lines into an array:
$data =3D file('myfile.txt');
foreach ($data AS $row) {
$row =3D explode("\n", trim($row));
var_dump($row);
}
And there you go.
Cheers.
On 24 October 2010 16:46, Ethan Rosenberg wrote:
> Dear list -
>
> Thanks for all your help.
>
> I have a tab delimited file which I wish to import into a data base. =C2=
=A0In
> MySQL I can use the LOAD DATA command. Â As far as I know, that comma=
nd
> cannot be used in PHP as a mysqli_query. Â As I understand, I have to=
parse
> the file and use the INSERT command.
>
> How do I do it? Â Code samples, please.
>
> Thanks.
>
> Ethan
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--=20
Andrés G. Montañez
Zend Certified Engineer
Montevideo - Uruguay
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Parsing Tab Delimited file
am 24.10.2010 21:17:20 von Niel Archer
> Dear list -
>
> Thanks for all your help.
>
> I have a tab delimited file which I wish to import into a data
> base. In MySQL I can use the LOAD DATA command. As far as I know,
> that command cannot be used in PHP as a mysqli_query. As I
> understand, I have to parse the file and use the INSERT command.
It can be done, IF the MySQL server allows you to do it.. Check the
servers configuration.
> How do I do it? Code samples, please.
>
> Thanks.
>
> Ethan
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Niel Archer
niel.archer (at) blueyonder.co.uk
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Parsing Tab Delimited file
am 26.10.2010 15:51:21 von Ethan Rosenberg
At 02:54 PM 10/24/2010, Jason Pruim wrote:
>On Oct 24, 2010, at 2:46 PM, Ethan Rosenberg wrote:
>
>>Dear list -
>>
>>Thanks for all your help.
>>
>>I have a tab delimited file which I wish to import into a data
>>base. In MySQL I can use the LOAD DATA command. As far as I know,
>>that command cannot be used in PHP as a mysqli_query. As I
>>understand, I have to parse the file and use the INSERT command.
>>
>>How do I do it? Code samples, please.
>>
>>Thanks.
>
>http://tinyurl.com/2fnm48f
>
>
++++++++++
Jayson -
Sorry for the delay.
Thanks. With what you and Andres send, it works beautifully.
Ethan
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Parsing Tab Delimited file
am 26.10.2010 15:52:09 von Ethan Rosenberg
At 02:56 PM 10/24/2010, Andrés G. Montañez wrote:
>Hi Ethan,
>
>fist you need to read the file, you could use the file() function
>which reads the file as an array, being each line an element;
>the you have to navigate the array and exploding the lines into an array:
>
>$data =3D file('myfile.txt');
>
>foreach ($data AS $row) {
> $row =3D explode("\n", trim($row));
> var_dump($row);
>}
>
>And there you go.
>
>Cheers.
>
>On 24 October 2010 16:46, Ethan Rosenberg wrote:
> > Dear list -
> >
> > Thanks for all your help.
> >
> > I have a tab delimited file which I wish to import into a data base. =C2=
In
> > MySQL I can use the LOAD DATA command. =C2 As far as I know, that=
command
> > cannot be used in PHP as a mysqli_query. =C2 As I understand, I have to=
parse
> > the file and use the INSERT command.
> >
> > How do I do it? =C2 Code samples, please.
> >
> > Thanks.
> >
> > Ethan
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
>
>--
>Andrés G. Montañez
>Zend Certified Engineer
>Montevideo - Uruguay
++++++++
Andres -
Sorry for the delay.
Thanks. With what you and Jayson sent, it works beautifully.
Ethan=20
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Parsing Tab Delimited file
am 26.10.2010 16:14:48 von Richard Quadling
On 26 October 2010 14:52, Ethan Rosenberg wrote:
> At 02:56 PM 10/24/2010, Andrés G. Montañez wrote:
>>
>> Hi Ethan,
>>
>> fist you need to read the file, you could use the file() function
>> which reads the file as an array, being each line an element;
>> the you have to navigate the array and exploding the lines into an array=
:
>>
>> $data =3D file('myfile.txt');
>>
>> foreach ($data AS $row) {
>> Â $row =3D explode("\n", trim($row));
>> Â var_dump($row);
>> }
>>
>> And there you go.
>>
>> Cheers.
>>
>> On 24 October 2010 16:46, Ethan Rosenberg wrote:
>> > Dear list -
>> >
>> > Thanks for all your help.
>> >
>> > I have a tab delimited file which I wish to import into a data base. =
Ã
>> > In
>> > MySQL I can use the LOAD DATA command. Ã As far as I know, that c=
ommand
>> > cannot be used in PHP as a mysqli_query. Ã As I understand, I hav=
e to
>> > parse
>> > the file and use the INSERT command.
>> >
>> > How do I do it? Ã Code samples, please.
>> >
>> > Thanks.
>> >
>> > Ethan
>> >
>> >
>> >
>> > --
>> > PHP Database Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>>
>>
>>
>> --
>> Andrés G. Montañez
>> Zend Certified Engineer
>> Montevideo - Uruguay
>
> ++++++++
> Andres -
>
> Sorry for the delay.
>
> Thanks. Â With what you and Jayson sent, Â it works beautifully.
>
> Ethan
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If you need to break the tab file apart then fgetcsv() is probably
going to help.
Just use "\t" for the $delimiter.
Pretty much.
But that's assuming you aren't using a mysql tool to import the data
directly. (I do a BULK INSERT in MS SQL).
--=20
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php