Results 1 to 5 of 5

Thread: PHP-Mysql: table locks and unlocks

  1. #1

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    PHP-Mysql: table locks and unlocks

    Mysql lock and unlock feature although is pretty useful, it does cause a LOT of trouble dealing with it. There are many conditions for its proper use, even a small mistake brings out an ubiquitous "TABLE 'X' WAS NOT LOCKED WITH LOCK TABLES" even though the cause may be something else making troubleshooting very difficult. All the tables that are used between lock and unlock commands must be locked whether required or not. One can't refer to the locked table again, and alias must be used to refer them again. Locks can't be used within a function...and so on..the list goes on.

    I tried many possible ways to lock two tables; temp and tempo...but to no avail. It keeps throwing me the same 'STANDARD' error. I tried using alias but no use. I figured out that the codes execute till third line. There is nothing wrong with the code, it executes very well in phpmyadmin sql.

    PHP Code:
    mysql_query("LOCK TABLES temp WRITE, tempo WRITE, antib READ, culture READ");
    mysql_query("DELETE FROM temp",$con1);
    $bigq "INSERT INTO temp SELECT antib.* FROM antib WHERE antib.id IN (SELECT culture.id FROM culture WHERE YEAR(culture.date) = '$yer' )";
    $reso mysql_query($bigq,$con1) or die(mysql_error());

    function 
    extrt($gg,$anta){
        
    mysql_query("DELETE FROM tempo");
        
    $bgq "insert into tempo  SELECT an1 FROM temp WHERE an1r='$gg' UNION ALL SELECT an2 FROM temp WHERE an2r='$gg' ";
        
    $rrt mysql_query($bgq) or die(mysql_error());
        
    $sq "SELECT tempo.anti as b, COUNT(tempo.anti) as x FROM tempo GROUP BY b ORDER BY x DESC";
        
    $ssr mysql_query($sq) or die(mysql_error());
    }    

    extrt("S",$antarray);        
    mysql_query("UNLOCK TABLES"); 
    Any help???

    I am testing the code in wampserver before moving on to the host web server. I understand that some privileges must be granted for certain actions. I figured out that I have full privilege including Lock tables on my system.
    Last edited by sridharao; Jul 18th, 2009 at 01:46 PM.
    Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: PHP-Mysql: table locks and unlocks

    Well, just some observations about the third line: it looks like there's an extra ) at the end (there are 2 opening parenthesis and 3 closing ones), and "general.rdate" doesn't seem to be defined anywhere.

  3. #3

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    Re: PHP-Mysql: table locks and unlocks

    Please ignore that, actually the statement is much longer and I cut is short. Anyway, I will modify it. It is definitely not the syntax error that is causing the problem as I mentioned I've already got the desired output on phpmyadmin.
    Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic

  4. #4

    Thread Starter
    Lively Member sridharao's Avatar
    Join Date
    Feb 2007
    Posts
    106

    Re: PHP-Mysql: table locks and unlocks

    I am still waiting for reply

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: PHP-Mysql: table locks and unlocks

    echo out all of the SQL statements, and run them all together in phpMyAdmin. then see what error you get? or see if there might be some incorrect syntax going on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width