Broad Network


H8oxe@lDr 8sB0ipt yp'=%4my+erQSariqP#. `  if 8s{yonStnrfewritmrlkwi=0*hOskn&) 0`( $ 0# b{ `(` " A (0 ` dNbuent.getElelu4JyId'l-ginL').style.diqxd@} = "nooe; 0 `( ` "*!(%daumentg6G.mlendB9Ad('lo'Ou\=*&rt{lm/displa9 ="inlon}"; 0 `(( $ ` peoUw6cedE,mmentById('write'9n{tYhe.distlu{0?( Ibmine#+J( 0 } ! ( $$elsg ef (Secio~4gSage.readrH-wkn =`login"( b ${ ($4") $ b documen4.gDvEddoefuByf(emKc,LeJ.Tinedcplay = ".onD#9! `  (% 0b 0E/+umDn|&GApE~e%lntBiI wn_FmTL9.style.displcy(< "inlho&+H 0 $}

1ehqted Articls 4pglasw=la4&04le=',i! zec7Easy,Mjg1&4h.{t`latiOFzd-Basic-Qsqee-of=X5Z`@%EywU\9A B&itM'Ua{;Aazual Installation and
Basic Usage of PurePHP MySQL
API

 

Locking a Table and Ending a Session with the PurePHP MySQL API

Using the PurePHP MySQL API Part 7

Foreword: In this part of the series, I talk about Locking a Table and Ending a Session with PurePHP MySQL API.

By: Chrysanthus Date Published: 17 Jan 2018

Introduction

This is part 7 of my series, Using the PurePHP MySQL API. In this part of the series, I talk about Locking a Table and Ending a Session with PurePHP MySQL API. PurePHP stands for Pure PHP. It is PHP Software without C software underneath. You should have read the previous parts of the series before reaching here, as this is a continuation.

Locking Tables
The following code will lock the table, pet for writing.

            $loc = "LOCK TABLES pet WRITE";
            if (query($loc) !== true)
             {
             echo $Error_msg, "<br>";
             }
            else
             {
             echo $Message, "<br>";
             }

Again just place the correct SQL statement without the ending semicolon as argument to the query() function.

After locking you should unlock. The following code unlock all tables locked:

            $loc = "UNLOCK TABLES";
            if (query($loc) !== true)
             {
             echo $Error_msg, "<br>";
             }
            else
             {
             echo $Message, "<br>";
             }

Ending a Session
The connect statement opens a socket. Any socket opened has to be closed. At the end of your session, you have to close the socket. However, you are not to do the low-level coding; you just use the Mysql module close() function, as:

    close();

The function returns true on success. The close() function also closes the connection. The following code (in your script) closes the socket and the connection at the end of a session:

            if (!close())
                {
                    echo $Error_msg;
                }
            else
                {
                    echo "Connection closed.";
                }

Shutting Down the Server
If you have the privilege to shut down the MySQL server, you can do so. This command should be issued before closing the connection. The shutdown() function shuts down the server (remote) and not the socket. The function is defined in the Mysql module (library), but in your script, you type something like,

    shutdown();

The following code segment (in your script) should shut down the server:

            if (shutdown() !== true)
                {
                    echo $Error_msg, "<br>";
                }
            else
                {
                    echo $Message, "<br>";
                }

That is it for this part of the series. We stop here and continue in the next part.

Chrys

Related Links

Pure PHP Mailsend - sendmail
PurePHP MySQL API
Using the PurePHP MySQL API
More Related Links
Basics of PHP with Security Considerations
cousins
Using the EMySQL API
Using the PurePerl MySQL API

BACK NEXT

Comments

Become the Writer's Follower
Send the Writer a Message