Hello All,

i don't know if it's appropiate to post this question on this list but i'm wondering how to fill a huge csv file in a postgresql database.

with the php script below, i got the following error:
X-Powered-By: PHP/4.2.2
Content-type: text/html

<br />
<b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>/var/www/html/csv/filldb</b> on line <b>51</b><br />

Does anyone have any idea?

Thx
Nat
_____________________________________________________
PHP script to fill DB:

#!/usr/bin/php
<?
$dbname="gb";
$table="gb";
$filename="TMP_PAS.TXT";

$database=pg_connect("dbname=$dbname");
if(!$database)
die("<center>Base de donné $db_name inaccessible.<br>Veuillez contacter

Pascal TUFENKJI</center>");

$q="select * from $table";
$ex=pg_exec($database,$q);
if(!$ex)
die("erreur");
$num=pg_numfields($ex);
for($i=0;$i<$num;$i++)
{ $fields.=$sep.pg_fieldname($ex,$i);
$sep=',';
}

$file=fopen("upload/$filename","r");
if(!$file)
die("Ouverture du fichier .csv impossible");

while($data=fgetcsv($file,1000,","))
{ $nb=count($data);
$values="";
$sp="";

//Au cas oùy a une séence
if($sequence)
{ $seqname=$table."_seq";
$values="nextval('$seqname'),";
}


for($c=0;$c<$nb;$c++)
{ $data[$c]=addslashes($data[$c]);
$data[$c]=trim($data[$c]);

if($data[$c]!="")
$values.=$sp."'".$data[$c]."'";
else
$values.=$sp."null";
$sp=',';
}

$dst="set datestyle to 'european'";
pg_exec($database,$dst);

$ins="insert into $table ($fields) values ($values)";
//echo "$ins<br>";
$exec=pg_exec($database,$ins);
if(!$exec)
die("Erreur d'insertion");
/*else
echo "$data[0] <b>OK</b><br>";*/
}
?>



_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail



--
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to