PHP implements multi-machine interlocking instances by inserting mysql data, mysql instance_PHP tutorial

WBOY
Release: 2016-07-13 10:15:10
Original
980 people have browsed it

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.

A simple PHP database insert/read example





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>>

php implements a simple registration page and inserts the registration information into the mysql database

注册页面: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 "注册成功";
%>
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/906674.htmlTechArticlePHP通过插入mysql数据来实现多机互锁实例,mysql实例 本文实例讲述了PHP通过插入mysql数据来实现多机互锁的方法,分享给大家供大家参考。具...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!