
What is CRUD? Titters aside, it’s probably not what you think. This common acronym stands for Create, Read, Update, Delete and it is a cornerstone of web development.
CRUD describes a process fundamental to all website developments and platforms, whether PHP, .NET, React or whatever. If it’s online, it has been subject to at least steps C and R. Someone created it and you’re reading it.
So common is the term and so fundamental the process that developers will talk about ‘creating the CRUD pages’ as a single task.
What Each Step Means
CREATE
Whatever it is – a product, a post, a page – every online entity must be created. Typically, entities are created on administrators’ pages, but not always. Anonymous website users (or those with a minimal level of authentication) can often leave comments. Creation requires input, and this normally takes place through a form – a product form is a complex, multi-field interactive affair. But it can be much simpler – tapping a ‘like‘ icon or submitting an online comment is a CREATE action. CRUD is everywhere.
A key feature of CREATE processes is data validation. A well-programmed Create process will ensure every piece of data recorded is in the correct format (is that email address properly formatted) and valid (is that email address used by a recognised member). Numbers must be numeric; text must be sanitised and so on.
Particularly important, created data must be relational. On creation, a record for a comment must contain a reference (or ID) for the parent post, a product image must contain a reference to the parent product and so on.
READ
Once the data has been created it can be READ and published to the rest of the world. This can be in aggregate (show me the number of ‘Likes’ my post got) or specific (show me that comment).
READing is often the simplest part of the development process. Web designers deal with the output of a READ process: display that product image, style that description, assemble those data into a table, emphasise that price.
But the data may be read many ways – into a table, onto a dedicated page, into a set of search results and so on.
UPDATE
It stands to reason. Things change. Most data is not binary. A like either exists or it doesn’t but everything else will need to be updated now and again. Prices change as do opinions and phone numbers. Typically, the process of updating looks very like the process for creating. A similar form, pre-populated with the existing record data and, on submission, the existing record is changed.
Much as with creation, all data must be validated before submission.
DELETE
Once event is over, the product de-listed or the page no longer relevant, an entity needs to be deleted. Deleting is more technical than it sounds. If the item you need to delete, for example, a user account what will happen to the comments they left and the purchases they made?
It is hard to programme for the absence of things. References to elements in a data structure which no longer exist can cause application errors and security loopholes.
Deleting from a database requires planning across the application. Counter-intuitively, it may well be the most technical part of the process.
Implementing CRUD in PHP
In PHP development, CRUD operations necessitate a combination of frontend and backend expertise. The frontend captures user inputs and displays information, while the backend, often written in PHP, interacts with the database to execute these operations. PHP’s compatibility with various databases, like MySQL, makes it a popular choice for implementing CRUD functionalities.
As in all languages, the predictable steps required mean frameworks such as Laravel and Symfony streamline the CRUD implementation process. A good framework will help provide robust structures for building secure and scalable applications and take repetition and excessive code out of the development.