in reply to Binary File Handles and Scalars
In Perl binary files don't like me.
Nor do databases, as far as I can see... :)
Since you are not asking anything specific, let me point out a few things that you should focus on:
First, your connection code.
This code can't possibly work. I can accept that you are using fake parameters for presentation's sake, but 'NULL' is not something you can safely pass to a DBI connection method. But even assuming that your connection syntax is accepted by any driver, (not by MySQL, which you say you're using), your $dbh can't return an error string in case of failure. If connect fails, then $dbh is undefined. You must get the error string from $DBI::errstr.my $dsn = 'NULL'; my $db_user_name = 'NULL'; my $db_password = 'NULL'; my $dbh = DBI->connect($dsn, $db_user_name, $db_password) || die $dbh- +>errstr;
You are using this construct several times:
$query->execute() || die $dbh->errstr; while( $a = $query->fetchrow_array() ) { push( @results, $a ); } return @results;
Why not using fetchall_arrayref instead?
my $records = $query->fetchall_arrayref; return @$records;
See DBI Recipes for more examples (and for something useful for the next item as well.)
Also, several times you are using
WHERE ID = \'$_[0]\'
Code like this is subject to SQL injection. It can be also the source of some hard-to-catch mistakes. Let me chant one of the Monastery mantras: "Use Placeholders!"
_ _ _ _ (_|| | |(_|>< _|
|
|---|