<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mary Jeykle</title>
    <description>The latest articles on Forem by Mary Jeykle (@mjdsunas).</description>
    <link>https://forem.com/mjdsunas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F583262%2Fb799685a-5a65-423e-a14e-933edead9cfe.jpeg</url>
      <title>Forem: Mary Jeykle</title>
      <link>https://forem.com/mjdsunas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mjdsunas"/>
    <language>en</language>
    <item>
      <title>Code Fast &amp; Code Smart: Productivity Tools for PHP</title>
      <dc:creator>Mary Jeykle</dc:creator>
      <pubDate>Tue, 16 Mar 2021 00:47:25 +0000</pubDate>
      <link>https://forem.com/mjdsunas/code-fast-code-smart-using-productivity-tools-for-php-1ekf</link>
      <guid>https://forem.com/mjdsunas/code-fast-code-smart-using-productivity-tools-for-php-1ekf</guid>
      <description>&lt;p&gt;Development tools plays an important role in the entire web development process. They say, your web app is only as good as your dev tool(s)! So, it is important to choose and study your Dev Tools before jumping in to web development. As it wil save you both in time and financial resources.&lt;/p&gt;

&lt;p&gt;To help you out, here are a list of essential tools for PHP web development to get you started. &lt;/p&gt;

&lt;h3&gt;
  
  
  Visual Studio Code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;https://code.visualstudio.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Java, Python, PHP, Go) and runtimes (such as .NET and Unity). Begin your journey with VS Code with these &lt;a href="https://code.visualstudio.com/docs/getstarted/introvideos" rel="noopener noreferrer"&gt;introductory videos&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fvsc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fvsc.PNG" alt="Visual Studio Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  CodeIgniter USER GUIDE
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.codeigniter.com/user_guide/" rel="noopener noreferrer"&gt;https://www.codeigniter.com/user_guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are using CodeIgniter framework in your PHP projects, before trying to search for 'answers' in your coding problems in W3Schools or stackoverflow, try reading the CodeIgniter User Guide first. It is the primary documentation for CodeIgniter, included in the package downloads. The User Guide can also be read online. It contains an introduction, tutorial, a number of "how to" guides, and then reference documentation for the components that make up the framework.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Generator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://generatedata.com" rel="noopener noreferrer"&gt;http://generatedata.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ever needed custom formatted sample / test data, like, bad? Well, that's the idea of this script. It's a free, open source tool written in JavaScript, PHP and MySQL that lets you quickly generate large volumes of custom data in a variety of formats for use in testing software, populating databases, and... so on and so forth.&lt;/p&gt;

&lt;p&gt;This site also offers an online demo where you're welcome to tinker around to get a sense of what the script does, what features it offers and how it works. Then, once you've whet your appetite, there's a free, fully functional, GNU-licensed version available for download. Alternatively, if you want to avoid the hassle of setting it up on your own server, you can donate $20 or more to get an account on the site, letting you generate up to 5,000 records at a time (instead of the maximum 100), and let you save your data sets. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fgenerate.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fgenerate.PNG" alt="Generate Data"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bootstrap Builder
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://getbootstrap.com/docs/3.3/components/" rel="noopener noreferrer"&gt;http://getbootstrap.com/docs/3.3/components&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile first projects on the web. This site give developers over a dozen of reusable components built to provide iconography, dropdowns, input groups, navigation, alerts, and much more. &lt;/p&gt;

&lt;h3&gt;
  
  
  Bootstrap Components Generator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://bootsnipp.com" rel="noopener noreferrer"&gt;https://bootsnipp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bootsnipp is an element gallery for web designers and web developers, anybody using Bootstrap will find this website essential in their craft. It is a free to use web service that provides code snippets for design elements on webpages. You can search for a particular webpage design element or simply browse them through the homepage. Clicking on an element opens its page where you can preview it and copy its code snippet. The code can be edited on the page and the preview is updated in real time.&lt;/p&gt;

&lt;p&gt;You can then copy the code and use it in your projects if you are using Bootstrap HTML / CSS / JS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sweet Alerts!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://sweetalert.js.org/guides/" rel="noopener noreferrer"&gt;https://sweetalert.js.org/guides&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SweetAlert makes popup messages easy and pretty. It is a beautiful replacement for success messages, error messages, warning modals, and a lot more. You can customize SweetAlert to fit your needs. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Falerts.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Falerts.PNG" alt="Sweet Alert"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  JSON Format viewer
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://jsonviewer.stack.hu/" rel="noopener noreferrer"&gt;http://jsonviewer.stack.hu/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JSON, short for JavaScript Object Notation, is a lightweight computer data interchange format. JSON is a text-based, human-readable format for representing simple data structures and associative arrays (called objects).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "firstName": "John",
  "lastName": "Smith",
  "gender": "man",
  "age": 32,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "fax",
      "number": "646 555-4567"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This site convert JSON Strings to a Friendly Readable Format. Like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fjson.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fjson.PNG" alt="JSON Viewer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  DataTables
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.datatables.net" rel="noopener noreferrer"&gt;https://www.datatables.net&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DataTables is a powerful jQuery plugin for creating table listings and adding interactions to them. It provides searching, sorting and pagination without any configuration. Help developers save time in creating advance and interactive HTML Tables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fdatatables.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fdatatables.PNG" alt="DataTables"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  PHPMAKER: Rapid Application Development (RAD) Tool for PHP
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://www.hkvstore.com/phpmaker" rel="noopener noreferrer"&gt;http://www.hkvstore.com/phpmaker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PHPMaker is a powerful automation tool that can generate a full set of PHP quickly from MySQL, PostgreSQL, Microsoft Access, Microsoft SQL Server, Oracle and SQLite databases. Using PHPMaker, you can instantly create web sites that allow users to view, edit, search, add and delete records on the web. PHPMaker is designed for high flexibility, numerous options enable you to generate PHP applications that best suits your needs. The generated codes are clean, straightforward and easy-to-customize. The PHP scripts can be run on Windows servers or Linux servers (except Microsoft Access). PHPMaker can save you tons of time and is suitable for both beginners and experienced develpers alike.&lt;/p&gt;

&lt;h3&gt;
  
  
  Make and receive phone calls and send and receive text messages using web service APIs
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.twilio.com/" rel="noopener noreferrer"&gt;https://www.twilio.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Twilio is a cloud communications platform as a service (CPaaS) company based in San Francisco, California. Twilio allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Halt bots using reCAPTCHA
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.google.com/recaptcha/intro/v3beta.html" rel="noopener noreferrer"&gt;https://www.google.com/recaptcha/intro/v3beta.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;reCAPTCHA is a free service that protects your website from spam and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive CAPTCHAs to keep automated software from engaging in abusive activities on your site. It does this while letting your valid users pass through with ease.&lt;/p&gt;

&lt;p&gt;reCAPTCHA offers more than just spam protection. Every time our CAPTCHAs are solved, that human effort helps digitize text, annotate images, and build machine learning datasets. This in turn helps preserve books, improve maps, and solve hard AI problems.&lt;/p&gt;

&lt;p&gt;You can find a reCAPTCHA &lt;a href="https://codelabs.developers.google.com/codelabs/reCAPTCHA/index.html#0" rel="noopener noreferrer"&gt;codelab here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Google Charts for Data Visualization
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/chart/" rel="noopener noreferrer"&gt;https://developers.google.com/chart/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Google Charts provides a perfect way to visualize data on your website. From simple line charts to complex hierarchical tree maps, the chart gallery provides a large number of ready-to-use chart types.&lt;/p&gt;

&lt;p&gt;The most common way to use Google Charts is with simple JavaScript that you embed in your web page. You load some Google Chart libraries, list the data to be charted, select options to customize your chart, and finally create a chart object with an id that you choose. Then, later in the web page, you create a &lt;/p&gt; with that id to display the Google Chart.

&lt;p&gt;That's all you need to &lt;a href="https://developers.google.com/chart/interactive/docs/quick_start" rel="noopener noreferrer"&gt;get started&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fcharts.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fcharts.PNG" alt="Google Chart"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Web Audit Tool
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://web.dev/measure" rel="noopener noreferrer"&gt;https://web.dev/measure&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Measure you website performance with this tool. It uses Lighthouse, is an open-source, automated tool for improving the quality of your web apps. It is integrated directly into the Chrome DevTools Audits panel. See your site's performance across the areas you care about. And get tips for improving your website.&lt;/p&gt;

</description>
      <category>php</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Audit Trail Implementation to CRUD Operation</title>
      <dc:creator>Mary Jeykle</dc:creator>
      <pubDate>Sun, 21 Feb 2021 08:24:10 +0000</pubDate>
      <link>https://forem.com/mjdsunas/audit-trail-implementation-to-crud-operation-255l</link>
      <guid>https://forem.com/mjdsunas/audit-trail-implementation-to-crud-operation-255l</guid>
      <description>&lt;p&gt;Every programmer has had to deal with CRUD functionality in most of their projects specially on applications that utilizes forms to retrieve and return data from a database. Here is a simple app with CRUD functionality. &lt;a href="https://github.com/mjdsunas/ciapp" rel="noopener noreferrer"&gt;Download or clone the app here&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Below is the simple CRUD created: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fcrud_list.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fcrud_list.png" alt="crud list"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s DB table look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fcrud_tbl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fcrud_tbl.png" alt="crud table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Audit trails are implemented to maintain a record of system activity. This is to keep track of what changes were made to the database, and by whom. &lt;/p&gt;

&lt;p&gt;Implementing audit trail may be performed either by program code or database procedures/triggers. We can start by altering the DB table &lt;strong&gt;tblitem&lt;/strong&gt; and add additional fields to implement the trail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audit Trail implementation for CREATE
&lt;/h2&gt;

&lt;p&gt;1) Add the fields &lt;strong&gt;added_by&lt;/strong&gt; and &lt;strong&gt;date_added&lt;/strong&gt; to DB table &lt;strong&gt;tblitem&lt;/strong&gt; to capture who added the record and when was the record added.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;added_by: int (11), allow NULL, default: NULL 
date_added: timestamp, allow NULL, default: NULL 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Add a trigger to capture the current date &amp;amp; time and update the date_added field with the current timestamp. Name the trigger &lt;strong&gt;trigger_on_insert&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN
  SET NEW.date_added = CURRENT_TIMESTAMP;
END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Modify &lt;strong&gt;Item controller&lt;/strong&gt; global constructor by getting the session data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem1.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4) Add the session data to the &lt;strong&gt;Item controller insert() function&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem2.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5) Modify the &lt;strong&gt;ItemModel insert() function&lt;/strong&gt; by setting and adding the session data to the insert query&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem3.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeay! We just created an audit trail on who added the record and when was the record added. &lt;/p&gt;

&lt;p&gt;Now, test it! Try to add a new record in the CRUD application and check the DB table &lt;strong&gt;tblitem&lt;/strong&gt; if the record was inserted and fields &lt;strong&gt;added_by&lt;/strong&gt; and &lt;strong&gt;date_inserted&lt;/strong&gt; was populated by the session id and current timestamp.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audit Trail implementation for DELETE
&lt;/h2&gt;

&lt;p&gt;For delete operations, there are several ways to implement the trail depending on the data retention policy of the organization. Some organization do “hard delete” from the DB table and keep and deleted records to another DB table as archived tables. &lt;/p&gt;

&lt;p&gt;While other organization do “soft delete” by tagging the record “inactive” or “deleted” or “archived” and not showing it to the record list by filtering only the active records. &lt;/p&gt;

&lt;p&gt;Let’s try to do the “soft delete” approach.&lt;/p&gt;

&lt;p&gt;1) Add the following fields to &lt;strong&gt;tblitem&lt;/strong&gt; to capture if the record is deleted/inactive/archived,  who deleted the record and when was the record deleted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;archived: tinyint (1), allow NULL, default: 0 
archived_by: int (11), allow NULL, default: NULL 
date_archived: timestamp, allow NULL, default: NULL 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) Add a trigger to capture the current date &amp;amp; time and update the &lt;strong&gt;date_archived&lt;/strong&gt; field with the current timestamp. Name the trigger &lt;strong&gt;trigger_on_update&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN

     IF NEW.archived = 1 THEN
          SET NEW.date_archived = CURRENT_TIMESTAMP;

     ELSEIF NEW.archived = 0 THEN
          SET NEW.date_archived = NULL;          
          SET NEW.archived_by = NULL;          
     END IF;

     END IF;
END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Update the &lt;strong&gt;ItemModel destroy() function&lt;/strong&gt; by populating the &lt;strong&gt;archived&lt;/strong&gt; and &lt;strong&gt;archived_by&lt;/strong&gt; fields with the archived tag = ‘1’ and session id.    &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem4.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4) In the &lt;strong&gt;ItemModel getItems() function&lt;/strong&gt;, include a WHERE clause limiting the list with active records only. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem5.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yeay! We just created an audit trail on who deleted a record and when was the record deleted. &lt;/p&gt;

&lt;p&gt;Now, test it! Try to delete a record in the CRUD application and check the &lt;strong&gt;tblitem&lt;/strong&gt; if the record’s &lt;strong&gt;archived&lt;/strong&gt; field was updated with value ‘1’ and fields &lt;strong&gt;archived_by&lt;/strong&gt; and &lt;strong&gt;date_archived&lt;/strong&gt; was populated by the session id and current timestamp.&lt;/p&gt;

&lt;p&gt;At this point, the DB structure of &lt;strong&gt;tblitem&lt;/strong&gt; now look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem6.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And added the following triggers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem7.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Audit Trail implementation for UPDATE
&lt;/h2&gt;

&lt;p&gt;1) Create a new DB table &lt;strong&gt;audit_trail&lt;/strong&gt; having the below table structure &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem8.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) Update the &lt;strong&gt;trigger_on_update&lt;/strong&gt; at DB table &lt;strong&gt;tblitem&lt;/strong&gt; with the following script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN

     IF NEW.archived = 1 THEN
          SET NEW.date_archived = CURRENT_TIMESTAMP;

     ELSEIF NEW.archived = 0 THEN
          SET NEW.date_archived = NULL;          
          SET NEW.archived_by = NULL;          

          IF NEW.name &amp;lt;&amp;gt; OLD.name THEN
               INSERT INTO audit_trail (tbl_name, tbl_field,old_value,new_value,updated_by,date_updated,tblItem_id) VALUES ('tblItem','name',OLD.name,NEW.NAME,NEW.added_by,CURRENT_TIMESTAMP,NEW.id);
          END IF;

          IF NEW.description &amp;lt;&amp;gt; OLD.description THEN
               INSERT INTO audit_trail (tbl_name, tbl_field,old_value,new_value,updated_by,date_updated,tblItem_id) VALUES ('tblItem','description',OLD.description,NEW.description,NEW.added_by,CURRENT_TIMESTAMP,NEW.id);
          END IF;

          IF NEW.price &amp;lt;&amp;gt; OLD.price THEN
               INSERT INTO audit_trail (tbl_name, tbl_field,old_value,new_value,updated_by,date_updated,tblItem_id) VALUES ('tblItem','price',OLD.price,NEW.price,NEW.added_by,CURRENT_TIMESTAMP,NEW.id);
          END IF;

     END IF;
END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have implemented an audit trail during record update. We created an audit table that captured what was updated by logging the name of table and field updated, the old and new value of the record, who updated the data, and when was the data updated.   &lt;/p&gt;

&lt;p&gt;Here is a the DB table audit_trail populated with data after update operation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem9.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And DB table &lt;strong&gt;tblitem&lt;/strong&gt; now looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwwcodemanila.github.io%2FWWCodeManila-PHP%2Fcontents%2Fitem10.png" alt="audit"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>mysql</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
