Results 1 to 5 of 5

Thread: PHP-Mysql: table locks and unlocks

Threaded View

  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

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