Transactions

A transaction is an indivisible unit of work. That said, a transaction cannot be divided or separated. In databases, a transaction involves multiple queries that require successful execution. If successfully executed, the transaction is committed. If one of the queries fails to execute, a rollback should be used for the entire transaction or parts of…

PHP: MySQLi Fetch

The following are common methods used to fetch data from a database using MySQLi. mysqli_stmt_fetch() Fetch results from a prepared statement into the bound variables. mysqli_fetch_all() Fetches all result rows and returns the result set as an associative array, a numeric array, or both. Available only with mysqlnd. mysqli_fetch_array()Fetch a result row as an associative, a…

PHP: Abstraction

When we look at abstract classes, we need to focus on the “abstract methods” within the abstract class. In fact, the rule #1 when dealing with abstraction is: if we create an abstract method in any class, we must make the entire class abstract. This clearly shows the importance of abstract classes comes from its…

PHP: SPL Autoload Register

PHP allows including files in a very easy way. This is very useful when dealing with multiple classes. The spl_autoload_register(function) registers a function with the Standard PHP Library (SPL) __autoload queue. If the queue is not yet activated it will be activated. The function is a user defined function as seen in the example below.…

PHP: Variable Handling

unset() unset() destroys the specified variables. The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy. If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.

CSRF Protection

Cross-site request forgery (CSRF), also known as one-click attack or session riding, is a type of malicious exploit of a website where unauthorized commands are submitted from a trusted website user. Laravel makes it easy to protect your application from CSRF attacks by inspecting every incoming POST, PUT, PATCH, or DELETE for a secret session…

Laravel Helpers: Fluent Strings

<?php use Illuminate\Support\Str; //FLUENT STRINGS //after //returns everything after the given value in a string echo “<br>”.Str::of(‘My name is Rabie Akela’)->after(‘My name is’); //Rabie Akela //afterlast //returns everything after the last occurrence of the given value in a string echo “<br>”.Str::of(‘App\Http\Controllers\Controller’)->afterLast(‘\\’); //Controller //append //appends the given values to the string echo “<br>”.Str::of(‘Rabie’)->append(‘ Akela’); //Rabie Akela…