↓ Archives ↓

Category → PHP

Use PHP MySQL date format correctly

If you ever try to format date in PHP and MySQL, using date (datetime or timestamp) value directly from MySQL to PHP date() function, then you'll get a Notice level error, something like this:

Notice: A non well formed numeric value encountered in ... .. .

Additionally, PHP date() will always return January, 01 1970 if MySQL date is directly used. It means, there is a difference between date in PHP and date in MySQL (i.e. they are not compatible). PHP date function accepts Unix Timestamp,  which is different from MySQL date types (DATE, TIME, DATETIME, TIMESTAMP etc.)

So if you want to change your default MySQL date format (the way it looks) to a more suitable formatting using PHP date() function, then you'll have to convert MySQL date to Unix Timestamp. Continue reading →

How to run your first PHP CODE

Few beginners asked me this question, so here is the answer (I'll update this post from time to time to meet the visitors' interests):

The easiest way to start with PHP is using XAMPP Continue reading →

PHP include vs. require

PHP programmers regularly use the functions (or more appropriately language construct) include(), include_once(), require() and require_once(), to insert useful codes written in other files, in the flow of execution. Although these constructs are used quite interchangeably, there are actually significant differences among them, specially when you are building well designed applications. Although these differences are very well defined in PHP manual, I've noticed many programmers don't really consider them while coding. I hope this tutorial will help them towards a better coding practice. Continue reading →