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();


email: mandog

In reply to PHP vs Perl code compare by mandog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.