PHP inserts mysql data to implement multi-host mutual lock instances. mysql instance _ PHP Tutorial

Source: Internet
Author: User
PHP inserts mysql data to implement multi-host mutual lock instances and mysql instances. PHP inserts mysql data to implement multi-host mutual lock instances. This article describes how PHP inserts mysql data to implement multi-host mutual lock. PHP inserts mysql data to implement multi-host mutual lock instances and mysql instances

This article describes how PHP inserts mysql data to implement multi-host lock. The specific implementation method is as follows:

You can add a general lock before executing the process. The shell yoke function is as follows. if it succeeds, 0 is returned; otherwise, a non-0 value is returned:

The code is as follows:

Function get_lock ()
{
Local dataId = "$ {1 }"
Local dataDate = "$ {2 }"

Local SQL = "insert into t_trans_lock
(DataId, dataDate) values ('$ {dataId}', '$ {dataDate }');"
Echo $ {SQL} | $ {DB_PUBLIC}

Return $?
}

Release the lock when execution fails or ends.

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 help you design the PHP + MySQL program.


A simple example of database insertion/reading in PHP





Untitled Document </title>
</Head>



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 'asts '. 'classmat' ('id', 'name', 'nickname', 'birthday', 'home', 'Blood ', 'QQ', 'Weibo', 'Email ', 'phone ', 'hoby', 'food', 'sentence', 'giput', 'Lover ', 'keenon', 'Unforgettable', 'wanttobecome', 'ideal ', 'Other') VALUES ('". $ _ POST ['id']. "','". $ _ POST ['name']. "','". $ _ POST ['nickname']. "','". $ _ POST ['birthday']. "','". $ _ POST ['home']. "','". $ _ POST ['blood ']. "','". $ _ POST ['QQ'] ...... remaining full text>

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

Registration page: reg.html



Username: </td> </Td> </tr>
Password: </td> </Td> </tr>
Confirm password: </td> </Td> </tr>
Email: </td> </Td> </tr>
Tel: </td> </Td> </tr>
</Td> </tr>
</Table>
</Form>

Receiving page: 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 "registration successful ";
%>

Examples in this article describe how PHP inserts mysql data to implement multi-host lock. With...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.