Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem in trigger

Posted on 2009-06-27
5
Medium Priority
?
217 Views
Last Modified: 2012-05-07
hi

am using xampp.....working in php and mysql...

i created the following trigger

CREATE TRIGGER dte
before INSERT ON temp_billing
FOR EACH
ROW
BEGIN
SET NEW.t_dt = new.t_updtime;
END


temp_billing table has the following attributes....

test_id        mediumint
product      varchar(40)
t_dt             datetime
t_updtime    timestamp

the trigger query is working fine when i insert manually through phpmyadmin

but when i insert through php 0000-00-00 00:00:00 is getting stored in t_dt.......


my insert query is


$sql="insert into temp_billing(testid,product,t_dt) values ('$id','$prod','0000-00-00')";
$result=mysql_query($sql);


pls help
0
Comment
Question by:whspider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 14

Expert Comment

by:racek
ID: 24726755
CREATE TRIGGER dte
before INSERT ON temp_billing
FOR EACH
ROW
BEGIN
SET NEW.t_dt = NOW();
END
0
 

Author Comment

by:whspider
ID: 24727017
will this now() value differ from current time stamp value.....
0
 
LVL 14

Accepted Solution

by:
racek earned 2000 total points
ID: 24727230
no, because t_updtime  is  timestamp. If you want to be sure, use

CREATE TRIGGER dte
before INSERT ON temp_billing
FOR EACH
ROW
BEGIN
SET NEW.t_dt = NOW(), t_updtime = NOW();

END
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 24727539
The reason it works in phpMyAdmin and not through your own script is that phpMyAdmin fills in the values for anything you don't edit, so the query it sends is something like this:

INSERT INTO temp_billing(testid, product, t_dt, t_updtime) VALUES ('$id', '$prod', '0000-00-00', CURRENT_TIMESTAMP)

If you did the same, then your original trigger would work. However, using racek's version instead allows you to be lazy and still have it work like you expect.
0
 
LVL 14

Expert Comment

by:racek
ID: 24731300
Mz version make logic hidden in the trigger - it can be another advantage :-)
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question