Relational Database Management Systems (RDBMS) is a service or software used to create and manage databases based on a relational model scheme. It can be defined as an open-source relational database management system (RDBMS) with a client-server model.
Note: To aid improve your understanding of MySQL, some of the key terms used throughout the article have been defined. Below is a vivid explanation of the key terms that you need to acquaint yourself with:
- A database; This is a collection of organized data. It is a place where data is organized and stored. The term relational means that the data stored is organized in tables that relate to each other in several ways. If the software does not support the relational data model, it is referred to as a Database Management System (DBMS).
- Open source: It can be termed in simple terms as something free, and you cannot pay or be charged to acquire it. Also, in terms of software, open-source means that the current user has the freedom to use and modify it without restrictions. On most occasions, open-source software is easy to install since it does not contain complex install instructions. In addition, developers using open-source source code have room to customize the original code to fit their use and accommodate their needs and preferences.
- Client-server model: Computers that can install and run RDBMS software are known as clients. They access data by connecting to the RDBMS server. With this type of computer, a central server must distribute data to several different workstations networked together.
MySQL is one of the most popular Relational Database Management Systems (RDBMS) alongside MariaDB. It is used for data storage by web applications such as Twitter, YouTube, Facebook, Google, and Yahoo. MySQL is compatible with Linux, macOS, Microsoft Windows, and Ubuntu.
Note: MySQL was written in C and C++ programming languages.
How MySQL works
One or a couple of computers (clients) connect to a server using the same network. Each client makes a request from the Graphical User Interface (GUI) on their monitors, and the server then dishes out the desired output only if both ends understand each other. Below are the main processes carried out in the Mysql environment:
- Creating databases that are used to store and control data. It also defines the relationship of each table contained in the database.
- Clients can make requests by typing particular SQL statements on the MySQL server.
- The server application then responds by providing the requested data on the clients’ side.
Saving signatures with MySQL
This article tutorial relies on a signature pad. A signature pad is a jQuery plugin that helps in the creation of an HTML5 canvas-based pad. It then saves the drawn signature in JSON for future regeneration.
1. Include jquery.signaturepad.css, flashcanvas.js, jquery.js, jquery.signaturepad.js, json2.js in the HTML file that you have, like the one given in the provided example.
2. Create the HTML by following the example given (click on “the example”)
4. Remember that most elements can be configured.
The signature pad jQuery plugin will change an HTML form into a signature pad with two modes: DrawIt and TypeIt. In TypeIt mode, the user’s signature is generated automatically as HTML text. It is styled with @font-face, from the input field where their name is typed in. In DrawIt mode, one can draw their signature on the canvas element.
The signature that has been drawn is then written out to a hidden input field as a JSON array using JSON.stringify(). Since the signature is saved as JSON, it can be sent as part of the form and kept on file. The signature can then be regenerated into the canvas element to be displayed using the JSON array. The signature pad will work with either a mouse or touch device.
You can find more about the signature pad by clicking on Signature Pad Documentation.
Getting the signature
The signature pad will submit the signature and the rest of the form submission inside a hidden input field:
The simplest way to get the signature using PHP is with the $_POST superglobal.
In PHP, the best way to get information from a form is using PHP’s filter functions (you can find more about the filter functions by visiting the link provided). They offer a safer way to grab user input and get rid of unwanted information. However, using the $_POST array is not secure, and it may further lead to validation errors. To top it off, PHP does not lead to any errors if you attempt to access the user input without submitting the form.
From lib/save-signature.php: We can use filter FILTER_UNSAFE_RAW for the particular signature because we want to maintain all the information provided in the signature. For you to be more specific, you can use FILTER_VALIDATE_REGEX.
Validating the signature
The highly probable way of validating the signature would include running it through json_decode() and waiting to ascertain whether it can be decoded.
Note: You need to validate the name to ascertain that the correct one was entered.
Setting up the database
You require a few pieces of information on the database to store the signature. That is the signatory’s name and the signature. It would be wise to store quite a lot of information on the signature; at the very least, a hash of the signature, the signatory’s IP address, and the time when the signature was written. This is majorly for legal purposes.
Saving to the database
After everything has been validated, we can now save the signature to the database. The simplest way is to store the JSON representation of the signature in the database. If you want to create a file that contains a photograph, click on check out how to convert the signature to an image.
The best method is to use PHP’s PDO (click on it to learn more about it) to connect to databases. By opting for PDO:prepare(), This will help you gain some protection against SQL injection attacks.
Regenerating the signature
Nonetheless, MySQL is not the only(R)DBMS on the market, but it is most certainly popular. It gets the high preference because of the following reasons:
- Flexibility and ease of use: It gives one the leeway to modify the source code and suit your expectations, and the best part is that this level of freedom comes free of charge. This also includes the option to upgrade to the advanced commercial version. In addition, the installation process is relatively easy, and it does not take more than thirty (30) minutes.
- It offers superb performance: MySQL is backed up by many cluster servers, which essentially means that whether you store vast amounts of big e-commerce data or carry out heavy business intelligence tasks, MySQL will offer you optimum speed.
- It is industry-standard: Over the years, industries have been using MySQL, which essentially shows many resources for skilled developers.
- It is secure: When choosing the right RDBMS software, your data should be your primary concern. MySQL has an Access Privilege System and User Account Management which sets its security bar high. It also offers Host-based verification and password encryption.
- On-demand scalability: MySQL gives room for establishing deeply embedded apps using a minimal footprint, including those in massive warehouses that house terabytes of data.
- Comprehensive transactional support: MySQL has the top-notch robust engineers on the market. It is the go-to resolution for complete data integrity. It has features such as multi-version transaction support, long-term transaction support as well as unrestricted row-level locking.
- Round-the-clock uptime: MySQL provides a 24/7 uptime as well as a vast array of high availability solutions like master/slave replication configurations.
In summary, this article gives you an elaborate explanation of MySQL. It further provides links through which you can get further information regarding the mentioned subject, and all you need to do is click on the provided links. In addition to all that, this article offers you an easy-flowing procedure through which you can save a signature in MySQL.
This article further provides a link that explains how one can convert the signature to an image. It contains sub-headings that guide you in understanding the step-by-step flow of events. Moreover, you can find a brief explanation as to how MySQL works as well as the reasons as to why MySQL is a great choice just in case you were thinking of ditching it (pun intended).