Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Binary File Handles and Scalars

by gmax (Abbot)
on Dec 18, 2003 at 21:29 UTC ( #315663=note: print w/replies, xml ) Need Help??


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.

    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;
    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.
  • 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!"

 _  _ _  _  
(_|| | |(_|><
 _|   

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315663]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2022-12-03 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?