Programming Tips & Insights

When to use NoSQL (e.g. MongoDB) and when to use SQL (e.g. MySQL)?

NoSQL is mostly about document databases while SQL is about relational databases. NoSQL vs. SQL Documents vs. Tables MongoDB vs. MySQL Property vs. Entity The trick is 4: Property vs. Entity Design your data models on a piece of paper. Use MongoDB if … If you see more trivial *entities* such as category, tag, brand, …

When to use NoSQL (e.g. MongoDB) and when to use SQL (e.g. MySQL)? Read More »

How to link external code source folder in Eclipse PDT projects & Array initializer indentation size?

Code folders may be distributed across different locations and paths but you want to manage them in one Eclipse project. It’s easy to achieve this by linking code source in your Eclipse project. Right click on project Click “Properties” Select “PHP” > “Build Path” Click “Link Source…” Click “Browse” Select the code folder to link …

How to link external code source folder in Eclipse PDT projects & Array initializer indentation size? Read More »

Optimize for Large Number of Columns in a Wide MySQL Table

In addition to necessary indexes and proper SELECT queries (only select needed columns), for wide tables, 2 basic tips apply well: Define your column as small as possible. Avoid using dynamic columns such as VARCHAR or TEXT as much as possible when you have large number of columns per table. Try using fixed length columns …

Optimize for Large Number of Columns in a Wide MySQL Table Read More »

Firefox redirecting localhost to www.localhost.com

To avoid this annoying behavior of Firefox that redirects http://localhost to http://www.localhost.com when you are developing on the localhost, try one or more of the following tips: Use other browsers such as IE or Chrome. Use “127.0.0.1” instead of “localhost”. Make sure http://localhost is correctly configured and responding. Make sure C:\Windows\System32\drivers\etc\hosts has and only has …

Firefox redirecting localhost to www.localhost.com Read More »

Remove Gmail via Field and Add mailed-by & signed-by with PHP mail()

PHP mail() is a great function to easily send emails from your website server. If you have ever used it before in action, or are currently using mail() to send out emails from your website or application, chances are you would find Gmail to be very persistent in attaching a ‘via’ field to the from …

Remove Gmail via Field and Add mailed-by & signed-by with PHP mail() Read More »

Disable Source > Format (Ctrl + Shift + F) in Zend Eclipse PDT

It became a total mess when I selected the entire root directory of my project and accidentally clicked Source > Format in Zend Eclipse PDT. All the files were instantly re-formatted and saved in a manner I wasn’t comfortable with and there didn’t seem any easy way to undo these changes that had been applied …

Disable Source > Format (Ctrl + Shift + F) in Zend Eclipse PDT Read More »

PHP: Round to the Nearest 0.5 (1.0, 1.5, 2.0, 2.5, etc.)

The common practice of rounding, namely the round() function in PHP, is to round to the nearest decimal point, that is, 1.0, 2.0, 3.0, etc. or, 10, 20, 30, etc. For example, echo round(4.25, 0); // 4 echo round(3.1415926, 2); // 3.14 echo round(299792, -3); // 300000 When I’m trying to aggregate all the customer …

PHP: Round to the Nearest 0.5 (1.0, 1.5, 2.0, 2.5, etc.) Read More »

Change array() indentation and wrapped line indentation in Eclipse for PHP Developers

The default array() indentation of Eclipse for PHP Developers when you create an array seems to be 2 tabs which I think are too much. To reduce it to just 1 tab: Window => Preferences => PHP => Editor => Typing => formatter preference page => Edit… => Indentation => Default indentation of array initializers Or Window => …

Change array() indentation and wrapped line indentation in Eclipse for PHP Developers Read More »

500 Internet Server Error for Incorrect Permissions after Installing suPHP and Uploading PHP Script

Many’s the time after you have uploaded some PHP script to your server and point the web browser to the address it gives 500 Internet Server Error. If you have suPHP installed this is very likely because the uploaded PHP script (files and directories) have wrong permissions set to them. With regards to Linux permissions, …

500 Internet Server Error for Incorrect Permissions after Installing suPHP and Uploading PHP Script Read More »

MySQL: Incorrect key file error AND InnoDB: Error: unable to create temporary file; errno: 2

When I encounter the incorrect key file for table error, it’s almost certainly because the disk is full and MySQL can’t write to the tmpdir. The solution is simple, just move tmpdir to another partition with enough disk space. Open my.ini and change tmpdir to another directory with enough disk space. Restart MySQL and that …

MySQL: Incorrect key file error AND InnoDB: Error: unable to create temporary file; errno: 2 Read More »

Make phpMyAdmin Show Exact Number of Records for InnoDB Tables

By default, phpMyAdmin shows an estimated number of records for InnoDB tables that have more than 20,000 rows. It can vary by every fresh as much as 50% or even more. Makes it hard to get an exact number of records for the tables as we have to explicitly run an SQL query to do …

Make phpMyAdmin Show Exact Number of Records for InnoDB Tables Read More »

PHP preg_match() First Letter of a WordPress Post for Drop Cap Styling

While CSS3 can target the first letter of text inside an element, it’s still not universally supported across major browsers AND it doesn’t work well for elements that have child elements inside. The bullet proof way to target the first letter of a WordPress post would be to capture the content of the post in …

PHP preg_match() First Letter of a WordPress Post for Drop Cap Styling Read More »

PHP Getting the last xx bytes of a large text file

Sometimes the text files are very large and you don’t want to load it in memory before searching through it because it’s inefficient. You just want to get the last few bytes of the file because the latest additions / updates are there. This would help you: $fp = fopen(‘somefile.txt’, ‘r’); fseek($fp, -50, SEEK_END); // …

PHP Getting the last xx bytes of a large text file Read More »

PHP Class for Handling .htpasswd and .htgroup (Member Login & User Management)

Apache is a marvelous web server that offers .htpasswd and .htgroup for controlling restricted access to your website. By help of .htaccess, they work as a member login & user management system that is so simple and easy to deploy. You can even define user groups / roles with it. Basically, .htpasswd defines pairs of …

PHP Class for Handling .htpasswd and .htgroup (Member Login & User Management) Read More »

Scroll to Top