Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Building a Web Application with PHP and MariaDB: A Reference Guide
Building a Web Application with PHP and MariaDB: A Reference Guide

Building a Web Application with PHP and MariaDB: A Reference Guide: Build fast, secure, and interactive web applications using this comprehensive guide

Arrow left icon
Profile Icon Sai S Sriparasa
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (3 Ratings)
Paperback Jun 2014 200 pages 1st Edition
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Sai S Sriparasa
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (3 Ratings)
Paperback Jun 2014 200 pages 1st Edition
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Building a Web Application with PHP and MariaDB: A Reference Guide

Chapter 2. Advanced Programming with MariaDB

In the previous chapter, we have discussed basic operations that can be performed on MariaDB such as creating databases and tables, adding data, modifying data, deleting data, and retrieving the data. We have also worked with the basic techniques of sorting and filtering data in order to work with the targeted and specific datasets. In this chapter, we will work with the following advanced concepts:

  • Indexes
  • Stored procedures
  • Functions
  • Triggers

Enhancing the existing tables

Let's begin by making a few changes to the existing students table. We will be adding two columns to the students table that would store a student's username and password. This database will be used to support Student Portal that we will build at a later point. The information available in the username and password fields will be used to authenticate and authorize the student to login to the student portal. There are a couple of ways to facilitate these changes; the first method is to use the DROP TABLE DDL command to remove the existing students table and use the CREATE TABLE DDL command to create a new students table that would have the extra username and password fields. This method however causes loss of existing data. The second method is to use the ALTER TABLE DDL command to add new columns to the existing students table.

The following screenshot shows the usage of these commands for altering the students table:

Enhancing the existing tables

In this example, we have coupled...

Working with stored procedures

Using a stored procedure, we can wrap multiple SQL statements into a single unit that provides the integrity and consistency in which the SQL statements are executed. Assume that there are multiple developers performing the same set of tasks again and again, executing the same set of statements one at a time, in the same or a different order based on the developer's preferences. The process can be consolidated by putting these statements into a stored procedure. This single unit can be thoroughly tested for maintaining data integrity and executing consistency across different scenarios. Another reason why the stored procedures are preferred over a set of multiple SQL statements is the performance boost that the stored procedures provide. To build a stored procedure, we would need two things at a minimum, the first being the name of the stored procedure and the second being the body or the content inside the stored procedure. Let's write a simple...

Working with stored routines

Stored routines are similar to stored procedures; both of them contain a block of SQL statements. There are a few differences such as a stored routine cannot return a result set and that a stored routine has to return a value and therefore, not preferred over stored procedures. Stored routines are invoked using the SELECT statement and can interchangeably be called as functions. The SHA1 function that we are using is a system-built stored routine to generate hashes for strings. Let's build a simple stored routine that would return the full name of the student when a username is passed in as a parameter, as shown in the following screenshot:

Working with stored routines

Note

We will be using the fn_functionName convention for our stored routines.

We begin by using the CREATE FUNCTION DDL command, appended by the name of the function, to create the function. This function takes the student's username as a parameter and returns the full name of the student, if the student exists. In...

Working with triggers

In the last few sections, we have looked at different scenarios for adding, updating, and deleting data. These are considered to be common operations in an everyday environment. However, what if we would like to watch certain events and use these events to perform another operation? As in, have an audit table that keeps a track of the user on whom an operation was performed or, assuming that there is a limit on the number of students that can register for a course, subtract that number whenever a student registers for the course. In our case, let's take a look at how an audit table can be used to keep track of different operations on a user. MariaDB provides the TRIGGER statement, which is a chain reaction that is set off in response to a SQL DML operation such as INSERT, UPDATE, or DELETE. To track these changes, let's build an audit table that would hold the person who performed the operation, the time when the operation was made, the type of the operation...

Summary

In this chapter, we have covered a lot of advanced concepts such as altering tables, working with indexes and column characteristics, working with stored procedures, working with stored routines, and working with triggers. MariaDB offers many more advanced concepts and the concepts discussed in this chapter will lay a good foundation to acquire a better understanding of the more advanced database concepts. Now that we have talked about a few advanced concepts of MariaDB, let's switch gears and dive in to understand a popular programming paradigm called object-oriented programming and understand its implementation in PHP 5.

Left arrow icon Right arrow icon

Description

This is a step-by-step, tutorial guide designed to help readers transition from beginners to more experienced developers using clear explanations. The variety of examples will help readers build, secure, and host real-time web applications. If you are a developer who wants to use PHP and MariaDB to build web applications, this book is ideal for you. Beginners can use this book to start with the basics and learn how to build and host web applications. Seasoned PHP Developers can use this book to get familiar with the new features of PHP 5.4 and 5.5, unit testing, caching, security, and performance optimization.

What you will learn

  • Grasp basic as well as advanced programming techniques with PHP and MariaDB
  • Perform CRUD operations, aggregations, filtering, and joins
  • Execute DDL operations and work with stored procedures, stored routines, and triggers
  • Employ concepts of objectoriented programming in PHP
  • Get acquainted with the latest features offered by PHP 5.4 and 5.5
  • Work with unit testing
  • Conduct file operations and logging with PHP
  • Implement authentication and ACLs
  • Improve performance optimization and security

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 16, 2014
Length: 200 pages
Edition : 1st
Language : English
ISBN-13 : 9781783981625
Vendor :
Zend Technologies
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jun 16, 2014
Length: 200 pages
Edition : 1st
Language : English
ISBN-13 : 9781783981625
Vendor :
Zend Technologies
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 113.97
MariaDB Cookbook
€41.99
Mastering MariaDB
€41.99
Building a Web Application with PHP and MariaDB: A Reference Guide
€29.99
Total 113.97 Stars icon

Table of Contents

11 Chapters
1. CRUD Operations, Sorting, Filtering, and Joins Chevron down icon Chevron up icon
2. Advanced Programming with MariaDB Chevron down icon Chevron up icon
3. Advanced Programming with PHP Chevron down icon Chevron up icon
4. Setting Up Student Portal Chevron down icon Chevron up icon
5. Working with Files and Directories Chevron down icon Chevron up icon
6. Authentication and Access Control Chevron down icon Chevron up icon
7. Caching Chevron down icon Chevron up icon
8. REST API Chevron down icon Chevron up icon
9. Security Chevron down icon Chevron up icon
10. Performance Optimization Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(3 Ratings)
5 star 33.3%
4 star 66.7%
3 star 0%
2 star 0%
1 star 0%
Hrishikesh Sep 09, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have got this book to review. I have gone through most of chapters, its good for beigner who wants to learn PHP with MariaDB.And its also for web developer. It covers from basic level to expert level. It covers various major sections in depth like, Optimization, REST, Joins, Sorting, CRUD operation etc.
Amazon Verified review Amazon
Pethuru Raj Jul 27, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Book Title: Building a Web Application with PHP and MariaDB: A Reference GuideI got a copy of this book and took some solid time to go through this book. The IT infrastructures are fast-evolving to be cloud-enabled, software-defined, orchestrated, optimized, shared, and automated through the seamless and sagacious incorporation of highly competent technologies. However the application development, deployment and delivery complexities on the modern infrastructures are on the climb. That is, designing and developing multi-tier and enterprise-class web applications from the ground up is not an easy task due to various internal as well as external reasons. Therefore through the smart leverage of potential and promising technologies and tools, how to simplify and streamline web application implementation is therefore acquiring a lot of attention. In this book, the author has tried to explain the various capabilities of PHP and MariaDB technologies in collaboratively building futuristic web applications. He had started with a detailed erudition of both PHP and MariaDB. Thereafter he had focused on the non-functional aspects (such as security, scalability, etc.) of web applications.The first chapter is all about the CRUD Operations, Sorting, Filtering, and Joins and the second chapter illustrates how MariaDB facilitates advanced programming. The third chapter is allocated for explaining the nitty-gritty of PHP language for constructing modern applications. Then the author has jumped into a practical application development. The chapter 4 elucidates on setting up a student portal in order to expose how PHP and MariaDB works together in bringing up highly complex web applications such as portals, etc. Thereafter he has described how the security aspect of web application is being tackled. Caching has been an important ingredient in any web application and the chapter 7 is fully allotted for lighting up the vague cache technique. The chapter 8 introduces the readers to the concept of REST architecture, followed by building a REST API for our student portal. The chapter 9 deals with an introduction to the different security optimizations that can be performed for Apache, MariaDB, and PHP to secure the web application. Performance is an indispensable phenomenon for any web application and the author has taken pains in order to explain it very deeply and decisively. The chapter 10 describes the introduction of different performance optimization techniques that can be used to scale the application more effectively.I am sure that this book is a must for any web application developers, application managed services professionals and performance consultants. Further on, due to its extreme simplicity, project leaders and managers can benefit immensely through this well-written, easy-to-grasp and use book.
Amazon Verified review Amazon
Zeeshan Jun 26, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This is a reference guide, developers with knowledge of PHP, MariaDB (and/or MySQL) should get this book as a desktop guide and also for refreshing their knowledge, since a lot of things have been added to PHP 5+ and MariaDB, so syntax and best practices is what developers could learn from this book. For example, there is a new short array declaration in PHP 5.4 which allows squre brackets to be used to declare arrays. $arr2 = [1,2,3,4];This is something I learned from the book as well. Chapter 3 of the book has more. I will not reveal it all :)Chapter 4 gives a practical approach to building a PHP, MariaDB MVC application (Yes but don’t use it to build another Laravel clone please !! )Chapter 8 is interesting, it covers REST API and XML Feeds, something Web and Mobile developers would love.Overall the book is a great package for a LAMP guy/gal, but I feel for a reference guide there needs to be more content. But nevertheless a must have for PHP, MariaDB developers, this book certainly teaches you a few new tricks.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.