X-Original-To: pgsql-php@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A60CA4763DA for ; Thu, 30 Jan 2003 21:22:02 -0500 (EST) Received: from smtp.gssf.org (smtp.gssf.org [209.102.124.32]) by postgresql.org (Postfix) with ESMTP id C5D6347600E for ; Thu, 30 Jan 2003 21:22:01 -0500 (EST) Received: from r7m3j6 (pdx-ppp166.pop1.net [209.102.125.216]) by smtp.gssf.org (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id SAA25828 for ; Thu, 30 Jan 2003 18:23:45 -0800 From: hodges@xprt.net X-Authentication-Warning: smtp.gssf.org: Host pdx-ppp166.pop1.net [209.102.125.216] claimed to be r7m3j6 To: Date: Thu, 30 Jan 2003 18:21:07 -0800 MIME-Version: 1.0 Subject: Re: populating db with PHP Message-ID: <3E396D13.32108.30959D@localhost> References: In-reply-to: X-mailer: Pegasus Mail for Windows (v4.02) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/103 X-Sequence-Number: 1848 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 > $field_count = "10"; > $table = "abc123"; > if (!isset($argv[1])) die ("Usage: import \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 >