Subject | Re: [firebird-support] Import data from flat files |
---|---|
Author | Milan Babuskov |
Post date | 2003-09-29T17:55:47Z |
Oleg Lebedev wrote:
//---------------
ibase_connect('database', 'user', 'pass');
$sql = 'insert into your_table (column list,...) values (';
$fp = fopen('csv_file', 'r');
while ($line = fread($fp, 10000)
{
$data = explode(',', $line);
$values = '';
foreach ($data as $d) // quote the text
$values[] = "'" . $d . "'";
ibase_query($sql . implode(',', $values) . ')');
}
fclose($fp);
ibase_commit();
//---------------
Well, you need to add some error checking and stuff, but it can do the
job really nice.
--
Milan Babuskov
http://fbexport.sourceforge.net
> Sory, I fogot to mention that I need to be able to import files into theYou can write quick&dirty(TM) PHP script to do it. Something like this:
> FireBird database running on Linux RedHat 8.0. I have 1 GB of data to
> import, so I need a pretty fast utility for that. The best would be a
> similar to GBAK utility that can import data from flat files into DB
> tables.
> Any ideas?
> Thanks.
//---------------
ibase_connect('database', 'user', 'pass');
$sql = 'insert into your_table (column list,...) values (';
$fp = fopen('csv_file', 'r');
while ($line = fread($fp, 10000)
{
$data = explode(',', $line);
$values = '';
foreach ($data as $d) // quote the text
$values[] = "'" . $d . "'";
ibase_query($sql . implode(',', $values) . ')');
}
fclose($fp);
ibase_commit();
//---------------
Well, you need to add some error checking and stuff, but it can do the
job really nice.
--
Milan Babuskov
http://fbexport.sourceforge.net