Use PHP’s fputcsv without writing to a file

PHP’s fputcsv function is very useful for creating CSV files, but by default will write out to a file. There are a couple of tricks to be able to keep it all in memory or instead write the CSV data out directly to the web browser without having to write your own custom functions.

Categories PHP

Fix “access denied” error when parsing HTML as PHP with Nginx

If you are attempting to get files with a .html extension parsed as PHP with Nginx + php-fpm, you might get an "access denied" error in your browser, and the error message "Access to the script ‘…’ has been denied (see security.limit_extensions)" in your Nginx error log. This post shows how to allow html files to be parsed successfully as PHP with Nginx + php-fpm.

A gotcha with PHP’s PDO::FETCH_CLASS

PHP’s PDO has a nifty way of fetching database records into an object, but there’s a slight gotcha when also using a constructor which initializes the class properties.

Categories PHP

Remove extension from a filename with PHP

If you’ve got a filename that you need to remove the extension from with PHP, there are a number of ways to do it. Here’s three ways, with some benchmarking.

Categories PHP

PHP PDO class to set the MySQL auto_increment_increment

A few days ago, I posted how to temporarily change the auto increment increment in MySQL. This post has an extension class to PHP's PDO to get the current auto increment value, change it to a new value and then reset it back to the original.