Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Debian DBD::ODBC select row by timestamp

by alexx_sh (Novice)
on Jul 23, 2012 at 17:09 UTC ( #983206=note: print w/ replies, xml ) Need Help??


in reply to Re: Debian DBD::ODBC select row by timestamp
in thread Debian DBD::ODBC select row by timestamp

Can you help me with code? I try read, but i can't write it by my self.


Comment on Re^2: Debian DBD::ODBC select row by timestamp
Re^3: Debian DBD::ODBC select row by timestamp
by CountZero (Bishop) on Jul 23, 2012 at 17:19 UTC
    my $sth = $dbh-> prepare (SELECT val from table where DD_MM_YYYY = ?); $sth->execute('2012-07-22 00:00:00');
    ? is the placeholder. It serves great use and it protects you against SQL injection attacks, by automatically quoting (and thereby neutralising) any "dangerous" characters.

    Of course you should add the usual or die ... checks to make sure no error happened. Also you have to verify the format of the DD_MM_YYY field to make sure your query sends in the timestamp in the right format.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      when i try your code i get err

      Search pattern not terminated at ./script.pl line 34.

      if i try code like this $dbh-> prepare ('SELECT val from table where DD_MM_YYYY = ?');

      Error at Line : syntax error near ?

        Can we see the script and the actual error messsage for the second case (including line number). The first case just needed quotes adding.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-09-19 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (135 votes), past polls