PHP通过插入mysql数据来实现多机互锁实例,mysql实例
本文实例讲述了PHP通过插入mysql数据来实现多机互锁的方法,分享给大家供大家参考。具体实现方法如下:
在执行流程之前可以加一般锁,shell枷锁函数如下,如果成功则会返回0,否则返回非0值:
复制代码 代码如下:
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 $?
}
在执行失败或者结束的时候释放锁
复制代码 代码如下:
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}
}
希望本文所述对大家的PHP+MySQL程序设计有所帮助。
#47;/W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/...al.dtd">
if(isset($_POST['tj']))//若点击了提交
{
$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']......余下全文>>
注册页面:reg.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
