Web & Software Developer

Code Snippets and Tutorials

PHP mktime() Changes Your Time, Here’s the Fix

If you’re using PHP mktime() to make a timestamp for a specific moment in time that should not change, then be sure to first set the default timezone to UTC. Otherwise, the dynamic behavior of mktime() is to modify or change your time, based on the timezone settings on your server. This may be desirable … Read more →

PHP strftime() is Faster Than date() in PHP 7

After running several benchmark tests, I find that the PHP strftime() is faster than date(). I tested each one creating the same datetime string in this format: ‘YYYY-MM-DD HH:MM’. The test iterates 100000 times over each function. I repeated this test several times. Each time, I alternated which function ran first. Here are the benchmark … Read more →

PHP – Check if INDEX or KEY Exists in MySQL Table

Here are some PHP functions to check if an INDEX exists in a MySQL table. Here is also a function that adds a new INDEX to a table. The first function lets you check for a specific INDEX (or KEY). The second function lists all indexes of a table, with their Key_name and Column_name. The … Read more →

PHP – Count Rows in MySQL Database Table

This is a quick PHP function to count rows in a MySQL database table. It takes 2 parameters, which are: $link This is the MySQL connection object which is made, for example, by using mysqli_connect() or mysqli_init(). $table The name of the table that you want to count rows for. The function will a return … Read more →