|
|
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:
#!/usr/bin/perl
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);
$sth->execute;
@row=$sth->fetchrow_array;
my $SystemName = @row[SystemName];
print "$SystemName\n";
$sth->finish;
Here is the PHP code:
<?php
@MYSQL_CONNECT("localhost","dbuser","dbpassword");
@mysql_select_db("somedb");
$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.
|
|