Counting database rows in MySQL and PHP

I help out fellow coders a lot on the PHP Freaks forums and I find a lot of new coders grasp PHP quickly but try to do too much in PHP that MySQL can handle in one query. Counting the number of rows in a select query is a good example.

Read more

Using MySQL date functions to save time in PHP

Ever since I started using PHP, if I ever needed to store a timestamp I always stored it as an INT. Only until recently have I switched over to using the DATETIME and TIMESTAMP data types in MySQL exclusively for any dates I needed. These fields are in the format of YYYY-MM-DD HH:MM:SS. When I first start using these field types, I didn’t know how to convert back and forth to a UNIX timestamp for use in PHP so I made a bunch of functions in PHP to convert between the two. That was until I found out about the MySQL date and time functions.

Read more