Blog

This blog is where I record notes on things I’m working on, problems I run into, and interesting resources I come across. Most of it is mainly for my own reference, but I hope some of it can be useful to others too. Posts range from quick observations to deeper dives into PHP, system design, and web development -- basically a peek into how I solve problems and experiment with ideas.

PHP Triple Equals (===) vs. Double Equals (==)

Triple equals = identity = the two expressions have same value and same type. Double equals = equality = the two expressions have same value (when converted to same type), but may or may not have the same type. Triple equals is the stronger condition. When triple equals is true, double equals is also true. When two things are identical, they must also be equal. But when double equals is true, triple [more ...]

Eliminating Redundant Fields in CMS Versioning to Reduce Cognitive Load

In my CMS, I track versions of site content. The original table looked like this: CREATE TABLE site_version ( version_id BIGINT(20) UNSIGNED NOT NULL, version_datetime DATETIME(3) NOT NULL, version_name VARCHAR(63) NOT NULL, description VARCHAR(255) NOT NULL DEFAULT '', notes MEDIUMTEXT NOT NULL DEFAULT '', PRIMARY KEY (version_id), UNIQUE KEY site_version_UN_version_name (version_name)) [more ...]

How to Check if Number is Decimal in PHP

This is how to check if variable is a decimal number in PHP (floating point number or numeric string representing a decimal number). The objective is a function which returns true for 5.28 and false for 5. But how about 5.00 - true or false? There are actually two variants of this problem: Check if number is not whole = not integer = has decimal places AND there is at least one non-zero after the decimal [more ...]

Email Length VARCHAR Limit in a User Database

This page is a summary of factors to consider when deciding maximum VARCHAR length of the email address field in a typical user database. There are theoretical limits (254 characters) based on IETF RFC. Therefore, the default data type is VARCHAR(254) if you want to accommodate every possible email. That said, vast majority of real emails are much shorter: 99.9%+ are below 40 characters based on various [more ...]

SQL TRUNCATE TABLE Statement

This page explains SQL TRUNCATE statement, what it does and how it differs from deleting all rows in a table. [toc]. **How to TRUNCATE a table.** Use the keywords TRUNCATE TABLE followed by table name. For example, this query truncates the table named historical_prices: TRUNCATE TABLE historical_prices; **TRUNCATE in different DMBS.** Note that TRUNCATE is not part of standard SQL. However, it is available [more ...]