Re: Load MySQL from a variable

From: Date: Tue, 21 Oct 2003 11:43:35 +0000
Subject: Re: Load MySQL from a variable
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-31219@lists.php.net to get a copy of this message
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...

« previous php.db (#31219) next »