1

im experiencing a problem where i have

one insert then sleep(25) then second insert.

datetime from first insert ALWAYS matches the datetime from second insert.

The problem is that both inserts happen at the same time after sleep. So i placed a condition for the second insert that checks for the first insert but the problem is there. I am using Zend DB select.

Notes: I have also tried live()->query($sql) and have the same results

            $sql = "insert into leads_verify
            (customer, lead_id,dt)
            values
            ('2'
            ,'111'
            ,'". date("Y-m-d H:i:s")."')";

            $queryResult = Db::live()->exec($sql);

            if($queryResult <> '5' ){
                sleep(24);
            }

            $sql2 = "insert into leads_verify
            (customer, lead_id,dt)
            values
            ('3'
            ,'222'
            ,'". date("Y-m-d H:i:s")."')";

                          $queryResult = Db::live()->exec($sql2);

The datetime of insertion is always the same for both. Any ideas?

7
  • 2
    Are you sure that $queryResult <> '5'? Try $queryResult !== 5 instead. Assumed that the query result is an integer
    – 321X
    Sep 25, 2012 at 19:12
  • A guess of mine is that the queries are not committed until the script exits or some other time later on. Sep 25, 2012 at 19:14
  • 1
    are you sure that the if condition matches? what if you comment it out?
    – RomanKonz
    Sep 25, 2012 at 19:16
  • var_dump($queryResult) and check it's value.
    – user4035
    Sep 25, 2012 at 20:04
  • @321x queryresults is always 1, i tested the !==5 and the problem occured. ExplosionPills - i think you are right, how can i force the query to execute? RomanKonz -the condition was put there on purpose to see if i can somehow force the first query. any ideas?
    – Val
    Sep 25, 2012 at 20:08

2 Answers 2

1

Are you using transactions in Zend?

then you need to commit your statements:

Db::live()->commit();

and by the way:
if the dt field is of the type DATE ore DATETIME, you can use Now() instead of '". date("Y-m-d H:i:s")."'

5
  • I thought about the commit/atomicity part, but if between a query and another there's 25 seconds' difference, and since he's using date(), rather than the SQL equivalent, I don't think commit would be the issue.
    – Christian
    Sep 25, 2012 at 22:16
  • I am not creating a transaction when i do these inserts. Not that i am aware of. I have added the commit to see how it works though IT WORKS!!!! also thanks for the now suggestion! :) you the man +1
    – Val
    Sep 25, 2012 at 23:11
  • It didnt work, i didnt notice the error that said there was no transaction to commit.
    – Val
    Sep 26, 2012 at 0:12
  • and what are the timestamps, if you use NOW()?
    – rubo77
    Sep 26, 2012 at 6:25
  • 1
    I changed to NOW() and the timestamps were identical. It must be overall transaction or something in the framework
    – Val
    Sep 27, 2012 at 16:58
0

The solution i used was to connect using mysql_query and run the sql that way. Thanks aLL

1
  • there was a transaction wrapper, which i removed and split into two transactions
    – Val
    Nov 6, 2012 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.