mandog has asked for the wisdom of the Perl Monks concerning the following question:
Some folks I respect are enthusiastic about PHP. I wrote the same toy script in both perl and PHP. So far I'm not sharing the love. Maybe it is because I've only got two hours experience with PHP?
Comments? I know there is at least one monk with a php site.
#!/usr/bin/php4 <?php dl("pgsql.so"); //kludge will be configured in // global php.ini soon $word=$HTTP_POST_VARS['word']; # no password needed as we are using suexec # and ident server locally $conn=pg_pconnect("user=mandog dbname=mandog"); if (!$conn) { print "bad databae connection!"; exit; } $query="INSERT INTO hello VALUES ('$word');"; $result=pg_exec($conn,$query); $query="SELECT word,to_char(when_hello,'Month DD HH24:MI:SS') FROM hel +lo;"; $result=pg_exec($conn,$query); if (!$result) { print "An error occured.\n"; exit; } $num = pg_numrows($result); print "<PRE>"; print "words of the moment\n"; for ($i=0; $i < $num; $i++) { $r = pg_fetch_row($result, $i); print "on: $r[1] the word was: \t$r[0]\n"; } print "</PRE>" ?> #!/usr/bin/perl -wT use strict; use CGI; use DBI; my $cgi=new CGI; print $cgi->header(); my $word=$cgi->param('word') || 'nothing entered for perl'; # RaiseError instead of manually dying # no password needed as we are using suexec and ident server locally my $dbh=DBI->connect('dbi:Pg:dbname=felicia','felicia', "",{ RaiseErro +r => 1}); my $query="INSERT INTO hello VALUES (?);"; my $sth=$dbh->prepare($query); $sth->execute($word); $query=$query="SELECT word,to_char(when_hello,'Month DD HH24:MI:SS') F +ROM hello;"; $sth=$dbh->prepare($query); $sth->execute(); print '<PRE>'; while (my @r=$sth->fetchrow_array()){ print "on: $r[1] the word was: \t$r[0]\n"; } print '</PRE>'; $dbh->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: PHP vs Perl code compare
by jeffa (Bishop) on Oct 28, 2002 at 00:32 UTC | |
by fruiture (Curate) on Oct 28, 2002 at 12:01 UTC | |
by broquaint (Abbot) on Oct 28, 2002 at 12:13 UTC | |
by fruiture (Curate) on Oct 28, 2002 at 13:44 UTC | |
by Xaositect (Friar) on Oct 28, 2002 at 19:16 UTC | |
|
Re: PHP vs Perl code compare
by mbadolato (Hermit) on Oct 28, 2002 at 05:01 UTC | |
by bart (Canon) on Oct 28, 2002 at 11:53 UTC | |
by broquaint (Abbot) on Oct 28, 2002 at 13:12 UTC |