Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate PostreSQL database using PHP

Status
Not open for further replies.

tanveer91

Programmer
Nov 13, 2001
31
GB
Hi all,

i'm new to php/postgres I have some records in csv format. My question is how can i populate my PostgreSQL Database by taking info from csv (spreadsheet) files?

your help is greatly appreciated.
 
suppose you have this table:
Users:
login,name

and the folloing CSV
smith, John Smith
brown, James Brown
and so on

you can populate your PgSQL db with this:

$file=file("users.csv");
while(list(,$value)=each($file)){
$array=explode(",",$value);
$query="INSERT INTO users (login,name) VALUES ('$array[0]','$array[1]')";
pgsql_query($query);
}

something like this will help you out. As i never used pgsql before i don't know exactly the functions and the sintaxe of them, so search for more info on this in

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top