Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Use mysql NOW() fuction from DBIx::Class

by alfarid23 (Initiate)
on Jul 16, 2007 at 01:08 UTC ( #626756=perlquestion: print w/ replies, xml ) Need Help??
alfarid23 has asked for the wisdom of the Perl Monks concerning the following question:

Hi I'm using DBIx::Class, and I'm fairly new to it. I'm trying to figure out how to update column value in a table with output of mysql NOW() function. Basically i just want to execute NOW() function in scalar context, capture output and update row. thank you

Comment on Use mysql NOW() fuction from DBIx::Class
Re: Use mysql NOW() fuction from DBIx::Class
by snopal (Pilgrim) on Jul 16, 2007 at 02:19 UTC

    You are asking a MySQL question.

    'SELECT NOW()' returns the value you seek.

    Also, MySQL offers a timestamp field for just such a purpose, so that you don't have to pre-acquire the date.

    You can construct a date value creating the well documented date syntax by the results of localtime.

    Take your choice.

      I think what snopal mentions is that while creating the table you can specify the column type as TIMESTAMP in MySQL. So then when you dealing with the table in Perl or whatever you can just ignore that column and go on working. On insertion of any value into the table, MySQL puts the time at that instant into the DB.

      If this is not you are asking, pardon me.
      He really is asking a DBIx::Class question. He doesn't know how to make DBIx::Class run that SQL. I don't either, but I would ask on the DBIx::Class mailing list rather than here.
Re: Use mysql NOW() fuction from DBIx::Class
by haoess (Curate) on Jul 16, 2007 at 07:03 UTC

    You can use NOW() in your UPDATE-clause:

    my $item = ...; $item->update({ time_column => \'NOW()', # more columns here });

    -- Frank

      Yep, a scalar reference passes a literal string to the SQL, rather than a bind variable.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-12-25 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls