http://www.perlmonks.org?node_id=626756

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

Replies are listed 'Best First'.
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.
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.