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.

PHP Magic Constants

There are nine magical constants that change depending on where they are used. All these “magical” constants are resolved at compile time, unlike regular constants, which are resolved at runtime. These special constants are case-insensitive and are as follows: __LINE__: The current line number of the file.__FILE__: The full path and filename of the file.__DIR__:…

PHP Release History

DATEEVENT 1995-06-08PHP 1.0 released (as PHP/FI) 1997-11-01PHP 2.0 released (as PHP/FI 2.0) 1998-06-06PHP 3.0 released 2000-05-22PHP 4, powered by the Zend Engine 1.0, was released 2000-10-20Support for PHP 3.0 ends 2001-06-23Support for PHP 4.0 ends 2001-12-10PHP 4.1 released 2002-03-12Support for PHP 4.1 ends 2002-04-22PHP 4.2 released 2002-09-06Support for PHP 4.2 ends 2002-12-27PHP 4.3 released 2004-07-01PHP…

Random and Shuffle

<?php echo ‘Random Number between 1000-9999 : ‘. rand(1000, 9999) . ‘<br>’; echo ‘Shuffle Letters in a String (ABCDE) : ‘. str_shuffle(“ABCDE”) . ‘<br>’; echo ‘Random (10) Bytes : ‘. random_bytes(10) . ‘<br>’; echo ‘bin2hex of 10 Bytes : ‘; var_dump(bin2hex(random_bytes(10))); ?>