pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
populating db with PHP
5+ messages / 4 participants
[nested] [flat]

* populating db with PHP
@ 2003-01-30 18:35 Bruce Becker <beckerba@pacbell.net>
  2003-01-30 19:45 ` Re: populating db with PHP David C. Brown <dbrown@centennialwines.com>
  2003-01-30 21:54 ` Re: populating db with PHP scott.marlowe <scott.marlowe@ihs.com>
  2003-01-31 02:21 ` Re: populating db with PHP hodges@xprt.net
  0 siblings, 3 replies; 5+ messages in thread

From: Bruce Becker @ 2003-01-30 18:35 UTC (permalink / raw)
  To: pgsql-php

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.
Thanks Brian.




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: populating db with PHP
  2003-01-30 18:35 populating db with PHP Bruce Becker <beckerba@pacbell.net>
@ 2003-01-30 19:45 ` David C. Brown <dbrown@centennialwines.com>
  2003-01-30 23:03   ` Re: populating db with PHP scott.marlowe <scott.marlowe@ihs.com>
  2 siblings, 1 reply; 5+ messages in thread

From: David C. Brown @ 2003-01-30 19:45 UTC (permalink / raw)
  To: beckerba@pacbell.net; +Cc: pgsql-php

php.net and phpbuilder.com are your best bets.  php.net is the best php 
resource I've found.  Personal I use it and #php IRC channels.

David

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.
>Thanks Brian.
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
>subscribe-nomail command to majordomo@postgresql.org so that your
>message can get through to the mailing list cleanly
>
>  
>




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: populating db with PHP
  2003-01-30 18:35 populating db with PHP Bruce Becker <beckerba@pacbell.net>
  2003-01-30 19:45 ` Re: populating db with PHP David C. Brown <dbrown@centennialwines.com>
@ 2003-01-30 23:03   ` scott.marlowe <scott.marlowe@ihs.com>
  0 siblings, 0 replies; 5+ messages in thread

From: scott.marlowe @ 2003-01-30 23:03 UTC (permalink / raw)
  To: David C. Brown <dbrown@centennialwines.com>; +Cc: beckerba@pacbell.net; pgsql-php

On Thu, 30 Jan 2003, David C. Brown wrote:

> php.net and phpbuilder.com are your best bets.  php.net is the best php 
> resource I've found.  Personal I use it and #php IRC channels.

Oh, and by the way, PHPBuilder.com should be considered one of our great 
wins, http://www.phpbuilder.com/columns/tim20001112.php3.  While 
Sourceforge has been forced from pgsql to db2 (with a resultant drop in 
any usefulness of a search query.) phpbuilder is still running on pgsql 
and doing quite nicely.




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: populating db with PHP
  2003-01-30 18:35 populating db with PHP Bruce Becker <beckerba@pacbell.net>
@ 2003-01-30 21:54 ` scott.marlowe <scott.marlowe@ihs.com>
  2 siblings, 0 replies; 5+ messages in thread

From: scott.marlowe @ 2003-01-30 21:54 UTC (permalink / raw)
  To: Bruce Becker <beckerba@pacbell.net>; +Cc: pgsql-php

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




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: populating db with PHP
  2003-01-30 18:35 populating db with PHP Bruce Becker <beckerba@pacbell.net>
@ 2003-01-31 02:21 ` hodges@xprt.net
  2 siblings, 0 replies; 5+ messages in thread

From: hodges@xprt.net @ 2003-01-31 02:21 UTC (permalink / raw)
  To: pgsql-php

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
> 





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2003-01-31 02:21 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-01-30 18:35 populating db with PHP Bruce Becker <beckerba@pacbell.net>
2003-01-30 19:45 ` David C. Brown <dbrown@centennialwines.com>
2003-01-30 23:03   ` scott.marlowe <scott.marlowe@ihs.com>
2003-01-30 21:54 ` scott.marlowe <scott.marlowe@ihs.com>
2003-01-31 02:21 ` hodges@xprt.net

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