Programming Tips & Insights

PHP: Create an Array

Array is probably the simplest compound data type every language supports. It’s basically a set of ordered values (text strings, numbers or booleans and even a child array). You can create an array in PHP by: $companies = array(‘Microsoft’, ‘Google’, ‘IBM’, ‘Apple’); Now array $companies contains 4 text string values. You can append one more …

PHP: Create an Array Read More »

Apache, PHP: Get Client Browser HTTP Request Headers Information

Every HTTP requests made by any client web browsers to an Apache should conform to the HTTP specification and provide certain set of headers information for the server to parse and understand. Useful headers information that can be retrieved in PHP by function apache_request_headers() includes: User-Agent: Operating System, browser and its version number, … Accept-Language: …

Apache, PHP: Get Client Browser HTTP Request Headers Information Read More »

Apache, PHP: Function to Get and Return PHP Version Number and Apache Version

To get the PHP version as well as the Apache version of the current host build, you will need the PHP function apache_get_version(): $ver = apache_get_version(); Sample output: Apache/2.2.6 (Win32) PHP/5.2.5 Which returns a string containing the Apache version number (2.2.6) as well as that of PHP (5.2.5). You can also get the PHP version …

Apache, PHP: Function to Get and Return PHP Version Number and Apache Version Read More »

Apache, PHP: Get Apache Enabled Modules in PHP Dynamically and Detect if a Apache Module is Installed

Sometimes you will need to detect if a certain Apache module is installed dynamically from PHP so as to determine for proper actions to take. For example, if you write inherent functionalities for optional SEO friendly URLs, you will want to know if the client host has the famous Apache module mod_rewrite installed and enabled, …

Apache, PHP: Get Apache Enabled Modules in PHP Dynamically and Detect if a Apache Module is Installed Read More »

PHP: Difference between htmlspecialchars() and htmlentities() Functions

2 functions exist in PHP to convert special characters to HTML entities (a kind of representations defined as in XML for web client such as browsers to recognize and render as special characters such as a spade: â™ , which can be represented as ♠ in HTML), namely htmlspecialchars() and htmlentities(). But what’s the difference? The …

PHP: Difference between htmlspecialchars() and htmlentities() Functions Read More »

PHP: open_basedir in php.ini to Restrict and Limit PHP File Accesses to a Certain Directory

The open_basedir directive in php.ini limits PHP file accesses (such as file opening, writing and deleting) within a designated directory such as /home/www/public_html so that it doesn’t endanger the rest of the system in any way. With proper Apache permissions and PHP installed as an Apache module, PHP inherits whatever privileges Apache has. As Apache …

PHP: open_basedir in php.ini to Restrict and Limit PHP File Accesses to a Certain Directory Read More »

Where is php.ini located?

Well it depends on the Linux distribution you are using, the version of php and the way you install it with Apache web server. Php.ini may be here: /etc/php.ini Or here: /etc/php/php.ini /etc/php5/php.ini Or here: /usr/bin/php5/bin/php.ini Anyway, you can always find any file named php.ini in this manner find / -name php.ini The simplest yet …

Where is php.ini located? Read More »

MySQL: Huge Table Not Responding after Adding Index

Today I’m optimizing some MySQL tables with large number of records — 1 million of them, yeah, I know — , it’s simply impossible to deal with such big chunks of data without proper indexing. So there I was, adding a variety of indexes to a few of the columns. It’s expected it’d take a …

MySQL: Huge Table Not Responding after Adding Index Read More »

MySQL: Counting Number of Records or Rows by a Foreign Column (from Another Table)

Well, MySQL doesn’t actually have anything called Foreign Key, it’s just my way of saying a alien column from another table. Let’s say 2 tables are related, 1 is books and the other is subjects. Any book in book table falls into one of the subjects, thus having a subject column referencing the ID of …

MySQL: Counting Number of Records or Rows by a Foreign Column (from Another Table) Read More »

MySQL: Update Multiple Rows or Records with One Single Query

As MySQL doesn’t have inherent support for updating more than one rows or records with a single update query as it does for insert query, in a situation which needs us to perform updating to tens of thousands or even millions of records, one update query for each row seems to be too much. Reducing …

MySQL: Update Multiple Rows or Records with One Single Query Read More »

MySQL: Replace Substring with Another String – the MySQL String Replace Function

To find / identify a part of an original string and replace it with another string in a SQL query with MySQL, use REPLACE(), the string replace function. For example, you may want to replace all spaces in one of the varchar or text fields to a single dash: UPDATE `table` SET `old_field` = REPLACE(`old_field`, …

MySQL: Replace Substring with Another String – the MySQL String Replace Function Read More »

MySQL: Deleting Duplicate Rows or Records | Selecting Unique Rows into A New Table

One of the principles of data integrity is to reduce data redundancy as much as possible and wipe out any duplicate database table entries. Another reason for this is that you need to add unique indexing to one or a group of table columns and you need the one column or combination of columns to …

MySQL: Deleting Duplicate Rows or Records | Selecting Unique Rows into A New Table Read More »

1 tip about ALTER TABLE xxx ADD INDEX yyy

Proper indexing can work wonders for large databases in query efficiency, it’s a compromise of disk storage in exchange for sorting speed. For databases with millions of records, indexing takes considerable amount of disk storage, and, AGONIZING lengths of time to create. I recently compiled a database with one table mytable consisting of over 4 …

1 tip about ALTER TABLE xxx ADD INDEX yyy Read More »

MySQL: INSERT INTO … SELECT … FROM … Selectively on Table Columns / Fields to Combine Multiple Tables into One

While you can always fulfill tasks such as creating a new table out of existing ones in MySQL by the help of PHP, it’d be much faster and way more efficient with native SQL queries. Consider when you need to combine a few tables into one, more precisely, you need just certain fields / columns …

MySQL: INSERT INTO … SELECT … FROM … Selectively on Table Columns / Fields to Combine Multiple Tables into One Read More »

MySQL: Insert if doesn’t exist otherwise update the existing row

A good practice of increasing SQL efficiency is to reduce the number of separate queries as much as possible. In a situation where you want a row updated if it exists and inserted if it doesn’t may take a newbie MySQL developer to write 2 independent queries, namely: first, check if the row exists with …

MySQL: Insert if doesn’t exist otherwise update the existing row Read More »

What is a programming framework?

Programmers write programs for users so certain processes in the workflow can be automated for efficiency and correctness. As such, to improve the programming efficiency of similar projects for addressing a common set of related problems, such as the need for content management system in web authoring, some programmers write programming frameworks to integrate the …

What is a programming framework? Read More »

Scroll to Top