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