Exporting to CSV on Mac's Excel using PHP's fgetcsv

PHP has a nice way of working with CSV files using the fgetcsv function. One of the downfalls in using the CSV format is dealing with what character is used for new lines, which is how nearly all CSV files determine the separation of rows.

If you are using excel on Mac and do not want to set your own newline character in PHP (or don’t have access to it!), when you save the file, choose Windows Comma Seperated (.csv) as the file type.

CodeIgniter Active Record vs. Explicit

When dealing with frameworks, such as Code Igniter, there is always a question of what type of overhead it adds to application. One rainy day not too long ago we ran some really simple tests on the difference between active record queries, and explicit queries in CI, and decided it might be nice to share the results. There is always the question of “is it faster”, and while our results show explicit SQL queries to be faster, database execution time is almost always negligible when compared to PHP run time, or page load speeds.

The Setup

We wanted to keep this test pretty bare-bones, so we could really nail down the overhead of just the active record processing. We loaded up a fresh copy of Code Igniter version 1.7.3, and created a typical controller-model relationship. Next, we created a simple timer using PHP’s microtime() function, and wrapped our calls in a for-loop, so it would repeat 1000 times. On each loop it logged the time difference of just the query itself, and at the end it exported to a .csv file so we could chart it up.

GET Query Times

Average Times (s) Explicit Query: 0.000168 Active Record Query: 0.000309

INSERT Query Times

Average Times (s) Explicit Query: 0.000161 Active Record Query: 0.000259

UPDATE Query Times

Average Times (s) Explicit Query: 0.000172 Active Record Query: 0.000321

DELETE Query Times

Average Times (s) Explicit Query: 0.000172 Active Record Query: 0.000321


As you might see, and as you might expect, there is a “significant” overhead using CI’s active record; however, I put that in quotations because the time scale we are looking at is so darn small. When you are building applications that require 10e-5 precision on your database queries, well, you probably aren’t a general-purpose, curious developer.