Broad Network


H8oxe@lDr¾ ‰ Î8sB0ipt ôyp'=%4my+erÏQSariqP#. `  if 8s{óyonStnråfeªwritmrlkwi®=ÿ0*hOskn&) °0`( $ 0# ¤ b{ `( ` " A (¤0 ` dNbuéent.getEleluê4JyId¨'l-ginL').style.diqxd@} = "nooe¦; 0 `( ` "*!(%daument®gå6G.mlendB9Ad('lo'OuÓ\=*&rt{lm/displa9 ="inlon}"; 0 `(( $ `  pèeoŒUÍáw6ŠcedE,mmentById('writeÊ'9n{tYhe.distlu{0?( Ibmine#+‰J(  0 } ! ¤( $$elsg ef (Seócio~4gSage.readårH-wkn ¼=¤`login"(Ž   b ${ ($4") $ b documen4.gDvEddoefuByÉf(emKcù,LeJ.Tinedécplay = ".onD#9‰! `  (% 0b 0E/+umDn|&GApE~e%lntBiI wn_F¯mTL§9.style.displcy(< "inlhoå&+H  0 $}

1ehqted Articlås 4pglasw=·la4&0ö4õle='¼,i! zec¹7Easy,Måjg1&4h.{t`lèatiOF­Ñzd-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