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

eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
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 : 9781783981632
Vendor :
Zend Technologies
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jun 16, 2014
Length: 200 pages
Edition : 1st
Language : English
ISBN-13 : 9781783981632
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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.