Re: Load MySQL from a variable

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

 



From: "Rory McKinley" <rorym@nebula.co.za>

> AFAIK, LOAD DATA INFILE will only work off a file. So you would have to
> create a temp file. Another option is to create a multiple value insert
> query e.g.
>
> INSERT INTO arb_table (arb_column_1...arb_column_n)
> VALUES (arb_value_1..arb_value_n), (arb_value_1..arb_value_n), .........

Making the above query should be as simple as:

$query = 'INSERT INTO arb_table (arb_column_1, arb_column_n) VALUES (' .
str_replace("\n","),\n(",$file_data) . ')';

where $file_data is your adjusted CSV file in a variable.

> Although LOAD DATA INFILE is, i think, the fastest way to get data into
> MySQL, if you first have to create a temp file, the additional nuisance
and
> time factors might make the above query a valid alternative.

Agree that LOAD DATA INFILE will probably still be faster overall, even with
the file write. Try each and see, though.

---John Holmes...

-- 
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