Broad Network


Developing a PurePerl MySQL API

Developing a PurePerl MySQL API – Part 1

Writing a Perl Module

Foreword: In this part of the series, I present an overview on developing a PurePerl Application Programming Interface for the MySQL database server.

By: Chrysanthus Date Published: 28 Jan 2015

Introduction

This is part 1 of my series, Developing a PurePerl MySQL API. In this part of the series, I present an overview on developing a PurePerl Application Programming Interface for the MySQL database server. An Application Programming Interface abbreviated, API is software that stands between two other software. An API facilitates communication between the two software. PurePerl stands for Pure Perl. It is Perl Software without C software underneath.

Pre-Knowledge
This series is part of my volume, Writing a Perl Module. At the bottom of this page, you have links to the different series in the volume. You should be reading the series in the order given.

In each series you should read the parts in the order given. For each part, the links and order are in a menu on the (top) left of the page.

The API
The API consists of Perl functions, which you use to access the MySQL server. The functions come in a module. To use the module, all you need to do is to learn how to use the functions and how to install the module – both processes are straight forward.

The MySQL Protocol has two phases: The Authentication Phase and The Query Phase. In this part of the article I talk about these phases briefly because I have already talked about them in the previous series. Here, I also talk about them as they are related to the API.

The Authentication Phase
This phase does the socket connection and the username and password login. The function called connect() in the API will carry out all the task of this phase.

The MySQL protocol packets concerned here, are the greeting, credentials, OK, command and Error packets. I talked about the greeting and credentials packets in detail in the previous part of the series; I will not talk about those two in this series. I will talk about the OK and Error packets in detail in this series. The command packet code I talk about in this series is just a bit different from the one of the previous series.

The Query Phase
Creating and selecting database, creating tables, altering tables, inserting rows, updating tables and selecting rows are all done in this phase.

The packets concerned with the query phase are the Data Packet, End-of-Data-Stream Packet, The Success Report Packet (OK), Command Packet and The Error Packet. I talk about these packets in detail in this series.

The command (query) packet is used a lot here; and the result can be, data packets, end-of-file (End-of-Data-Stream) packet, OK packet or Error packet.

Closing the Socket
Any socket or connection opened has to be closed. A socket is opened and a connection made in the authentication phase. This socket has to be closed. The API has a function to close the socket (connection).

The Functions
The functions are not many and are easy to use. To use the API, all you need to do is to learn how to use the functions and the simple installation process of the module (API): that’s all. You do not need to understand the details of this series, in order to use the functions. However, if you want to be able to produce your own similar API, then you should understand this series.

The authentication phase has one function; there are a number of functions for the commands; and then there is the close function.

Well, let us stop here, for now. We continue in the next part of the series, with the development of the connect() function, whose packets you should already be familiar with.

Chrys

Related Links

Internet Sockets and Perl
Perl pack and unpack Functions
Writing MySQL Protocol Packets in PurePerl
Developing a PurePerl MySQL API
Using the PurePerl MySQL API
More Related Links
Perl Mailsend
PurePerl MySQL API
Perl Course - Professional and Advanced
Major in Website Design
Web Development Course
Producing a Pure Perl Library
MySQL Course

NEXT

Comments

Become the Writer's Fan
Send the Writer a Message