root
By: a guest | Jun 30th, 2009 | Syntax:
None | Size: 0.49 KB | Hits: 7 | Expires: Never
#!/usr/bin/perl
use strict;
use DBI;
sub db_connect {
my $dsn = "delfi;host=localhost;mysql_enable_utf8=1";;
my $dbh = DBI->connect("dbi:mysql:$dsn", "mysql", "", { PrintError => 0, RaiseError => 1 });
return $dbh;
}
my $dbh = db_connect();
my $sth = $dbh->prepare("SELECT name FROM newsCategories WHERE ID=?");
$sth->execute(2);
my ($rootname) = $sth->fetchrow or die 'Non existing root category';
print "rex: ", $1, "\n" if $rootname =~ /^(...)/;
print "substr: ", substr($rootname, 0, 3) . '...';