Lock or restrict MySQL table rows
Use PHP to lock a MySQL table entries or rows. I have used this in licensing a software I had build.
I have build an office automation software insidei2 for which my company has decided to create licensing on the bases of users, ie you pay per user.
So I was asked to lock the database or table. Now I was wondering how can I do that, checked MySQL commands for the same, but couldnt find a simple answer, and it hit me…….. the answer was so easy.
I used my best pal PHP for it.
To restrict entries in a table I did the following:
$license=50;
$res=mysql_query(”select * from employee”) or die(mysql_error());
$totalrecords=mysql_num_rows($res);
if($totalrecords<=$license)
{ echo “Write code to add entries in the table”;} else {echo “Sorry, your license does not permit more than $license entries”;}
Explanation
| Define the max entries allowed | $license=50; |
| Open the table | $res=mysql_query(”select * from employee”) or die(mysql_error()); |
| Check the total entries | $totalrecords=mysql_num_rows($res); |
| If entries are more than or equal to allowed entries than add entries else do not add entries | if($totalrecords<=$license) { echo “Write code to add entries in the table”;} else {echo “Sorry, your license does not permit more than $license entries”;} |