[UPHPU] Re: database query order

Richard K Miller richardkmiller at gmail.com
Tue Sep 5 12:13:29 MDT 2006


On Sep 5, 2006, at 10:53 AM, Richard K Miller wrote:

> I've noticed that an UPDATE query that should come before the next  
> SELECT is actually coming after.
>
> The MySQL log shows the following, for instance:
>
> 10:47:32
> 	32 Connect
> 	32 Init DB
> 	33 Connect
> 	33 Init DB
> 	33 Query SELECT ...
>
> 10:47:33
> 	32 Query UPDATE ...
> 	33 Quit
> 	32 Quit
>
> I send the UPDATE statement before SELECT (notice the 32 vs. 33)  
> but it sometimes gets executed afterwards.  How do I force the  
> UPDATE to finish before the SELECT?  Do I need to switch from  
> MyISAM to InnoDB and use transactions or something?
>
> Richard
>
>

Executing a write lock (LOCK TABLES table WRITE) before the UPDATE is  
the correct way of doing this.  (UNLOCK TABLES after the UPDATE.)

I had tried this before, but the real solution was a PHP problem (not  
MySQL.)  I had one file redirecting to another with header("Location:  
"), but I had forgotten to put an exit() after the header().  As soon  
as I added exit(), the statements occurred in the correct order.



More information about the UPHPU mailing list