CRUD Archives | phpGrid - PHP Datagrid Create PHP grids in minutes, not hours. Wed, 02 Oct 2024 00:50:31 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 All You Need Is CRUD? https://phpgrid.com/blog/all-you-need-is-crud/ Wed, 02 Oct 2024 00:50:31 +0000 https://phpgrid.com/?p=10180

  Believe it or not, everything is essentially CRUD on the internet. It is the hidden skeleton that supports all of our digital interactions. What is CRUD? First of all, let’s get the jargon out of the way. CRUD stands for Create, Read, Update, and Delete — the four basic operations performed on data in a database […]

The post All You Need Is CRUD? appeared first on phpGrid - PHP Datagrid.

]]>

 

Believe it or not, everything is essentially CRUD on the internet. It is the hidden skeleton that supports all of our digital interactions.

What is CRUD?

First of all, let’s get the jargon out of the way. CRUD stands for Create, Read, Update, and Delete — the four basic operations performed on data in a database or application.

It’s not just about data entry forms or database management; CRUD operations are embedded in nearly every feature and action we perform in applications, including those that might seem more complex at first glance.

Let’s start with an example.

SAP is a massive CRUD

During my years in grad school, I had the pleasure (or displeasure) to use SAP ERP system The first time I launched SAP (back when it was still a Windows app), I was struck by its overwhelming number of datagrids. And not just a few — TONS of them, all intricately linked.

SAP interface with datagrids

Imagine navigating through this cluttered interface — it’s a German product, after all!

Despite its chaotic appearance, SAP’s core is packed with datagrids. These datagrids with columns and rows are fundamentally tied to CRUD operations (Create, Read, Update, Delete). They ensure that managing vast amounts of data is both efficient and intuitive, thanks to CRUD’s reliable framework.

SAP has improved is UI over the years, but datagrid still play an essential role at its core.

When there is datagrid, there must be CRUD (Create, Read, Update, Delete).

HTTP verbs are CRUD

Now, let’s talk about something you might use every day without realizing its connection to CRUD — HTTP verbs.

HTTP verbs (or methods) GET, POST, PUT, DELETE, and PATCH are essentially aligned with CRUD operations because they map directly to the fundamental actions required to manage resources in a web application.

Image credit: useful-web

Here’s how each HTTP verb corresponds to CRUD:

1. GET → Read

  • GET is used to retrieve data from a server, which corresponds to the Readoperation in CRUD. For example, when you visit a webpage or query an API to fetch information, the server processes a GET request to retrieve and return the requested data.

2. POST → Create

  • POST is used to send data to the server to create a new resource. This aligns with the Create operation in CRUD. For instance, submitting a form to create a new user account or adding a new item to a database typically involves a POST request.

3. PUT → Update

  • PUT is used to update an existing resource on the server. This corresponds to the Update operation in CRUD. PUT requests typically involve sending the complete updated resource to the server, which then replaces the existing resource with the new version

4. DELETE → Delete

  • DELETE is used to remove a resource from the server, which directly aligns with the Delete operation in CRUD. When a DELETE request is sent, the specified resource is removed from the server, reflecting the removal of a record in a database.

By designing HTTP verbs around CRUD concepts, web APIs can manage resources in a way that is both intuitive for developers and effective for data manipulation, maintaining consistency across different systems.

Not Convinced? Let’s Dig Deeper

You might be thinking, “Okay, there are lots of CRUDs, but does that really mean everything is CRUD?” You might argue that complex applications like Facebook or YouTube don’t fit into this model. Or do they?

Why Facebook is also just a CRUD

Post image

In 2016, Anatoly Lubarsky reverse-engineered Facebook’s database schema, revealing that at its core with user data is stored in relational databases, and CRUD operations manage and retrieve this data.

Whether it’s creating posts, reading news feeds, updating profiles, or deleting content, CRUD operations ensure data is consistently handled in the background, even as the complex processes remain invisible to the user.

Facebook’s Database reverse engineered by Anatoly Lubarsky

Users interact with the platform by creating posts, reading news feeds, updating profiles, and deleting content, all of which are underpinned by CRUD operations that ensure the data is consistently stored, retrieved, and modified in the database, while the complex backend processes remain invisible to the user.

Let’s break it down:

1. FB User Login

  • Read: When you log in to FB, the system reads (R) your input credentials (username and password) from the database to verify your identity.
  • Update: The system might update (U) the last login timestamp or session information in the database once you’re authenticated.
  • Create: If you log in for the first time or create a session, the system might create © a new session record.
  • Delete: Old session data or failed login attempts might be deleted (D) as part of maintaining security.

2. Reading FB posts

  • Read: Search operations are primarily about reading (R) data. When you search for something, the system queries the database and reads the relevant records that match your search criteria.
  • Create/Update/Delete: Though less obvious, search engines also involve creating, updating, and deleting indexes in the background to ensure fast and accurate results. For instance, when new content is added or updated on a platform, search indexes are updated (U) or new entries are created ©. When content is removed, those indexes are deleted (D).

3. Updating Profile

  • Updating profiles is a CRUD operation because it involves modifying existing data in the database. When a user changes their profile information, the system updates the corresponding record in the database

Still not convinced?

Let’s take a look at YouTube.

YouTube: A CRUD Classic

Post image

YouTube is actually a great example of a CRUD application. Here’s how YouTube fits into this model:

  1. Create
    Uploading Videos:
    Users can create content by uploading videos. This involves adding a new video record to the YouTube database, including metadata like the title, description, tags, and thumbnail.
  2. Read
    Watching Videos:
    The core functionality of YouTube is allowing users to read (consume) content. This involves retrieving video data from the database and streaming it to the user.
    Searching and Browsing: Users can search for videos, browse recommendations, and view playlists, all of which involve reading data from YouTube’s servers.
     
  3. Update
    Editing Videos:
    Users can update the metadata of their videos, such as changing the title, description, or privacy settings.
    Managing Playlists: Users can update their playlists by adding or removing videos, changing the order, or editing the playlist title and description.
     
  4. Delete
    Deleting Videos: Users can delete their videos, which removes the video and its associated data from YouTube’s database.
    Removing Content from Playlists: Users can also delete videos from playlists or remove entire playlists.

The Myth of Non-CRUD Operations

What I heard the most is that people would say, “My application has non-CRUD operations,” usually referring to complex functionalities that go beyond basic data management, such as real-time data processing, advanced analytics, complex business logic, or workflow automation, which involve more than just creating, reading, updating, or deleting records in a database.

Or are they?

CRUD in disguise

Datagrid is a CRUD, but not all CRUDs are datagrids. CRUD could have many forms and faces.

Even in situations involving complex functionalities like real-time data processing, advanced analytics, or workflow automation, CRUD operations are still essentially everywhere. These advanced features still rely on the underlying ability to create, read, update, or delete data as they interact with databases or data stores.

1. Real-Time Data Processing:

  • In a real-time data system such as stock trading platform that processes real-time data, CRUD operations are still involved. For instance, the system createsnew trade records when transactions occur, reads real-time market data to display to users, updates users’ portfolios with the latest values, and deletesoutdated or canceled orders. While the processing might be complex, the data handling at its core is still CRUD-based.

2. Advanced Analytics:

  • In a business intelligence tool that performs advanced analytics, CRUD operations are essential. The tool creates datasets based on user queries, readslarge volumes of data from various sources, updates dashboards with the latest analysis results, and deletes outdated reports. The sophisticated algorithms and visualizations rely on CRUD to manage and display the underlying data effectively.

3. Workflow Automation:

  • When you automate a workflow, what’s really happening? The system createsnew tasks, reads existing data (because it’s nosy like that), updates the status as things move along, and deletes anything that’s done or obsolete, kind of like cleaning out your closet but with data instead of last season’s shoes. So no matter how complex or high-tech the automation gets, at its core, it’s just CRUD — on autopilot, and maybe with a little more flair.

4. Machine Learning Applications:

  • In a machine learning platform, CRUD operations are involved in managing training datasets and model results. Even though machine learning is a mystical dance of algorithms and data, it’s still fueled by the trusty old CRUD operations — because even fancy AI models need their data served fresh, updated, and occasionally deleted.

Even though the applications may perform sophisticated tasks, add, read, update, delete operations are still the backbone of any data management system. CRUD remains essential to ensure that the application’s complex functionalities can operate effectively.

The list goes on and on.

Once You Spot CRUD, You’ll Start Seeing It Everywhere!

Once you understand how CRUD works, you’ll start recognizing its patterns in all kinds of software.

These four magic letters are so fundamental to data management, it quietly powers a wide variety of interactions — even ones that don’t seem obvious at first glance. The more familiar you are with this concept, the easier it becomes to see how deeply integrated it is in almost every digital system.

It’s like discovering the hidden building blocks behind the digital world.

All you need is CRUD!

Richard

The post All You Need Is CRUD? appeared first on phpGrid - PHP Datagrid.

]]>
10180
CRUD success/error status display https://phpgrid.com/example/crud-successerror-status-display/ Fri, 04 Nov 2016 00:33:57 +0000 http://phpgrid.com/?p=9050

Starting version 7, phpGrid now displays status of either success or error confirmation messages without configuration. There is no additional programming required to enable this new feature in 7.0. Prior to phpGrid version 7, you can simulate the notification with the following. 123456789<pre id="_changes_debug_ajaxresponse"></pre> <script type="text/javascript"> // replace "phpGridx" with your path to phpGrid $(document).ajaxComplete(function( […]

The post CRUD success/error status display appeared first on phpGrid - PHP Datagrid.

]]>

Starting version 7, phpGrid now displays status of either success or error confirmation messages without configuration. There is no additional programming required to enable this new feature in 7.0.

Prior to phpGrid version 7, you can simulate the notification with the following.

1
2
3
4
5
6
7
8
9
<pre id="_changes_debug_ajaxresponse"></pre>
<script type="text/javascript">
// replace "phpGridx" with your path to phpGrid
$(document).ajaxComplete(function( event, xhr, settings ) {
  if ( settings.url.split('?')[0] === "/<PATH TO PHPGRID FOLDER>/edit.php" ){  
    $("#_changes_debug_ajaxresponse").text(xhr.responseText);
  }
});
</script>

The post CRUD success/error status display appeared first on phpGrid - PHP Datagrid.

]]>
9050
set_edit_condition() https://phpgrid.com/documentation/set_edit_condition/ Fri, 11 Oct 2013 22:33:05 +0000 http://phpgrid.com/?p=2612 Parameters: $edit_conditoin: An array stores edit permission condition. Description: Set row-level permission condition for editing. Remark: This works for INLINE ONLY by hiding the edit icons using javascript, CSS For that reason, developers should still validate user permission at the database or on the server side. For complex conditions, use add_event and javascript. See row-level […]

The post set_edit_condition() appeared first on phpGrid - PHP Datagrid.

]]>
  • Parameters:
    • $edit_conditoin: An array stores edit permission condition.
  • Description:
    • Set row-level permission condition for editing.
  • Remark:
    • This works for INLINE ONLY by hiding the edit icons using javascript, CSS
    • For that reason, developers should still validate user permission at the database or on the server side.
    • For complex conditions, use add_event and javascript. See row-level edit permission example.
    • Example:
    1
    2
    $dg -> enable_edit('INLINE', 'CRUD');
    $dg -> set_edit_condition(array('status' => '=="Shipped"', '&&', 'customerNumber' => '==114' ));

    The above code snippet generates javascript that validates Status and customerNumber value. If both are true, the edit icon will appear.

    phpGrid_Custom_Edit_Condition_without_using_set_edit_condition

    The post set_edit_condition() appeared first on phpGrid - PHP Datagrid.

    ]]>
    2612
    enable_edit() * https://phpgrid.com/documentation/enable_editedit/ Tue, 14 Sep 2010 07:50:23 +0000 http://64.38.236.7/?p=372 * Please note this feature is only available in paid versions. CELL edit is only available in the commercial licenses Parameters: $edit_mode: FORM, INLINE, or CELL. The default is FORM. $operations: specify allowed datagrid edit operations. By default, all edit operations are allowed. C = Create R = Review U = Update D = Delete […]

    The post enable_edit() * appeared first on phpGrid - PHP Datagrid.

    ]]>
    * Please note this feature is only available in paid versions. CELL edit is only available in the commercial licenses

    • Parameters:
      • $edit_mode: FORM, INLINE, or CELL. The default is FORM.
      • $operations: specify allowed datagrid edit operations. By default, all edit operations are allowed.
        • C = Create
        • R = Review
        • U = Update
        • D = Delete
      • $edit_file: Optional. Use a custom edit file other than the default “edit.php”. Do not set this parameter unless you ABSOLUTELY know what you are doing!
    • Description:
      • When Form edit mode is used, additional icons appear in the data grid footer used for editing. When set to inline mode, the cells in the selected row become editable when the row is clicked. Only a single row can be edited for either mode.
    • Remark:
      • Multiple records can be deleted when multiple select is enabled. See set_multiselect() for more information on this method.
      • For inline edit, the user must press Enter key to save changes
      • In FORM edit mode,  double click triggers the popup edit window to display. In INLINE edit it is a single click to edit, similar to how Excel works. This is a design decision.
      • When edit mode set to ‘CELL’, the datagrid will behave like an Excel spreadsheet. It is advisable to also enable keyboard navigation with enable_kb_nav().
    • Example:
    1
    $dg -> enable_edit('FORM', 'CRU'); // Everything is allowed but delete

    It’s also possible to load a custom form in an iframe in a modal window with your own custom CRUD scripts. 

    Quick Tip: Keep the edit form open after submit

    To keep form open after submit, add the following javascript to override ‘closeAfterEdit’ value before </body>. Double click to edit a row, and form will remain open after edit.

    Replace “orders” with your table name.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    jQuery(document).ready(function($){
        var grid = $('#orders')[0];
        $(grid).jqGrid('setGridParam',{
                ondblClickRow: function(rowid) {
                    $(this).jqGrid('editGridRow', rowid,
                        {   recreateForm:true,
                            closeAfterEdit:false,
                            closeOnEscape:true,
                            reloadAfterSubmit:false})
                }
            });
    });

    The post enable_edit() * appeared first on phpGrid - PHP Datagrid.

    ]]> 372