PHP implements multi-machine interlocking instances by inserting mysql data, mysql instances
The example in this article describes how PHP achieves multi-machine interlocking by inserting mysql data. It is shared with everyone for your reference. The specific implementation method is as follows:
You can add a general lock before executing the process. The shell shackle function is as follows. If successful, it will return 0, otherwise it will return a non-zero value:
Copy code The code is as follows:
function get_lock()
{
Local dataId="${1}"
Local dataDate="${2}"
local sql="insert intot_trans_lock
(dataId, dataDate) values('${dataId}', '${dataDate}');"
echo ${sql} | ${DB_PUBLIC}
return $?
}
Release the lock when execution fails or ends
Copy code The code is as follows:
function free_lock()
{
Local dataId="${1}"
Local dataDate="${2}"
Local status="${3}"
local sql="delete from t_trans_lock
Where dataId='${dataId}' and dataDate='${dataDate}';"
echo ${sql} | ${DB_PUBLIC}
If [ $? -ne 0 ]; then
write_log ${dataId} "free lock failed"
fi
Return ${status}
}
I hope this article will be helpful to everyone’s PHP+MySQL programming.
Untitled Document if(isset($ _POST['tj']))//If you click submit
{
$conn=mysql_connect("localhost","username","password");
mysql_select_db("eastses" ,$conn);
mysql_query("set names utf8",$conn);
date_default_timezone_set("asia/chongqing");
$sql = "INSERT INTO `eastses`.`classmate` (` id`, `name`, `nickname`, `birthday`, `home`, `blood`, `qq`, `weibo`, `email`, `phone`, `hobby`, `food`, `sentence` , `gift`, `lover`, `keenon`, `unforgettable`, `wanttobecome`, `ideal`, `other`) VALUES ('".$_POST['id']."', '".$_POST ['name']."', '".$_POST['nickname']."', '".$_POST['birthday']."', '".$_POST['home']."' , '".$_POST['blood']."', '".$_POST['qq']......The rest of the text>>
注册页面:reg.html
接收页面:reg.php
<%php
$db = mysql_connect("localhost", "root", "12345");
mysql_select_db("dataname", $db);
mysql_query("insert into tablename(username, userpass, email, telphone) values('$_POST[username]', '$_POST[userpass]', '$_POST[email]', '$_POST[telphone]')");
echo "注册成功";
%>
http://www.bkjia.com/PHPjc/906674.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/906674.htmlTechArticlePHP通过插入mysql数据来实现多机互锁实例,mysql实例 本文实例讲述了PHP通过插入mysql数据来实现多机互锁的方法,分享给大家供大家参考。具...