PHP versus Perl
2003-07-15 17:49:45 ET

Perl's got some advantages when it comes to scripting and certain file manipulation work, but it's MySQL connectivity sucks. I'm hating it more and more.

First off, integrating MySQL (or even PostgressSQL, or even Oracle) into PHP is pretty easy to do at compile time.

./configure --with-mysql=/usr/local/mysql

Getting the DBI module, compiling it, and installing it was rather a pain, and very poorly setup and documented. There's inherent complexity, and then there's sloppy complexity.

Plus, the syntax seems overly complicated for Perl. Let's say I wanted to pull the data for SystemName from table System, where the SystemID was "4". Here is the Perl code:

use DBI();
my $dbh = DBI->connect("DBI:mysql:database=somedatabase;host=localhost", "dbuser", "dbpassword", {'RaiseError' => 1});
$query = "select SystemName from System where SystemID = '4'";
$sth = $dbh->prepare($query);
my $SystemName = @row[SystemName];
print "$SystemName\n";

Here is the PHP code:

$query = select SystemName from System where SystemID = '4'";
$result = safe_query($query); // safe_query is a popular function shortcut for PHP
$row = mysql_fetch_array($result);
$SystemName = $row['SystemName'];
echo $SystemName;

Maybe it's the time I've been spending with PHP lately, but the PHP way seems much easier to follow, and to troubleshoot. The $sth arrays seem fairly counter-intuitive, at least to me. Who knows.

2003-07-15 17:58:19 ET

do you use perl often?

2003-07-15 18:07:58 ET

I really, really hate perl. Perhaps tomorrow I will write a long rant about why I hate perl so much... but not tonight.

The whole DBI interface is abstracted so other database engines can easily be plugged into it. A questionably useful abstraction at that.

OK, my blood is beginning to boil, I best stop. ;)

2003-07-15 18:17:38 ET

Well I understand the benefit to abstraction, but the way it went about it seems rather weird and counterintuitive.

Perl is nice in it's flexiblity, but it's all over the damn place. CPAN helps some, but damn, it's annoying.

2003-07-15 18:38:34 ET

Perl was best when it was still at version 4.0.36. When 5 came along, with all of its OO gookieness, it all went to hell. It's still a great text processing language, but trying to do almost anything else that is non-trivial in it is difficult and makes you feel dirty afterwards.

2003-07-15 18:43:42 ET

*sits in corner of shower*


2003-07-15 19:10:20 ET

i dont know wtf you're talking about in this entry but you get cool points for watching aqua teen hunger force and home movies.

2003-07-16 05:00:18 ET

wow..i didnt understand a word you said

2003-07-16 05:16:35 ET

I should qualify my statements with the fact that I've used perl extensively throughout the last 10 years for various projects. And that is why I'm so critical of it ;)

2003-07-16 06:47:12 ET

I've used it quite a bit too, but only for scripting and text processing in a sysadmin realm. I've only recently needed to do DB stuff with it, and use some of Perl's extraneous modules. And it sucks.

2003-07-17 03:42:25 ET

haha i probably shouldnt read the thread either in hopes of sparing myself utter confusion

2003-07-31 15:06:17 ET

I think a lot of people rag on PERL and not all of it is warranted.

I've found PERL modules generally very easy to install (perl ; make ; make test && sudo make install)

Again, I have no beef with the syntax. However you may want to use placeholders and cached statements ... oh and strict and maybe taint. I also make a Config module for the specific project and have a Config::getHandle() call that returns a DB handle with all the required options for that project

#!/usr/bin/perl -wT
use DBI;
use strict;
use ConfigModule; // Or do ''

package DBTest;
my $dbh = Config::getHandle();
my $query = "SELECT SystemName FROM System WHERE SystemID = ?";
my $sth = $dbh->prepare_cached($query);

eval {
// If eval $@ gets set. This is one grip I have - crazy variable names no one knows the origin of, or what they necessarily mean ;)

if ($@) {

print "We get teh DB error: $@";

my $result = $sth->fetchrow_array(); // You'll only get one result, presumably


print "Row is: $row";

I will agree with m0xie though that at times you'll write some code (That'll do exactly what you want and pretty well for PERL) but you'll be sitting there thinking "_THAT_ is bad practice"

Oh, and that OO Perl is crazy.

  Return to shadeland's page