pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hodges@xprt.net
To: pgsql-php@postgresql.org
Subject: Re: populating db with PHP
Date: Thu, 30 Jan 2003 18:21:07 -0800
Message-ID: <3E396D13.32108.30959D@localhost> (raw)
In-Reply-To: <Pine.LNX.4.33.0301301448130.22730-100000@css120.ihs.com>
References: <NFBBIDKILBCFIHGCPNFGOEKFCDAA.beckerba@pacbell.net>

i found Julie Morani's Fast and Easy book from Thick Books
was an excellent start.
http://www.thickbook.com/index.html

Tom

On 30 Jan 2003 at 14:54, scott.marlowe wrote:

> On Thu, 30 Jan 2003, Bruce Becker wrote:
> 
> > Two questions: For someone using PHP for the first time, which book is
> > considered the best? Secondly could someone provide some sample code
> > or direct me to some sample code for populating a database using PHP.
> 
> Not a clue on best book, as I learned PHP so long ago there literally were 
> no books on it back then, and I've only skimmed over a few.  The online 
> manual is actually pretty good is short, and www.phpbuilder.com is a great 
> site for finding sample code and answers...
> 
> Here's a short php script for populating a database we actually use here 
> at work.  note that this is a shell script, i.e. it runs as a cron job at 
> night, not through the web server, but just like a command like program 
> like a perl script or anything else.  You can easily make it a web script, 
> just chop off the top line and put it in a web page.
> 
> #!/usr/local/bin/php -1
> <?php
> $field_count = "10";
> $table = "abc123";
> if (!isset($argv[1])) die ("Usage: import <filename>\n\n");
> else $filename = $argv[1];
> $conn = pg_connect("dbname=database user=bubbahotep host=bruce");
> pg_exec($conn,"begin");
> $fp = fopen($filename,"r");
> while (!feof($fp)) {
> 	$line = fgetcsv($fp,4096);
> 	if (count($line)!=$field_count) continue;
> 	$tmp = implode(":::::",$line);
> 	$tmp = pg_escape_string($tmp);
> 	$line = explode(":::::",$tmp);
> 	$query = "insert into $table values ('";
> 	$query.= implode("','",$line);
> 	$query.= "')";
> 	pg_exec($conn,$query);
> }
> pg_exec($conn,"end");
> ?>
> 
> 
> It's short and primitive, but it works well enough
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html
> 





view thread (5+ messages)

Message-ID: <3E396D13.32108.30959D@localhost>
Permalink:  ../3E396D13.32108.30959D@localhost/
Also on:    postgresql.org/message-id/3E396D13.32108.30959D@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: hodges@xprt.net
  Subject: Re: populating db with PHP
  In-Reply-To: <3E396D13.32108.30959D@localhost>
  References: <NFBBIDKILBCFIHGCPNFGOEKFCDAA.beckerba@pacbell.net> <3E396D13.32108.30959D@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox