Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Ireland

Premium delivery 7 - 10 business days

€23.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Ireland

Premium delivery 7 - 10 business days

€23.95
(Includes tracking information)

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
Banner background image

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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela