search
Homephp教程php手册PHP通过插入mysql数据来实现多机互锁实例,mysql实例

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程序设计有所帮助。

一个PHP简单的插入数据库/读取示例

#47;/W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/...al.dtd">



无标题文档<br><br><br>

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']......余下全文>>
 

php 实现简单的注册页面 并把注册信息插入到 mysql 数据库中

注册页面:reg.html



用户名:
密码:
确认密码:
邮箱:
电话:




接收页面:reg.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 "注册成功";
%>
 
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

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

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

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

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.