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???:confused:
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.
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.
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.
Re: PHP-Mysql: table locks and unlocks
I am still waiting for reply
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.