Nuita S Tue Jun 25 17:00:43 -0400 2013

Subject: My experience with activerecord

I have spend a few hours trying to make it work.

The library is rather hard to use due to lack of documentation. If you read the doc from the start, one of the first things you're told is to create a model. But you're not told what a model is. If you read the rest of the doc, still no definition of a model. So you try to guess and goes to the next step.

You try to do basic things, like inserting a row and getting the last insert id. Nothing in the doc. The "basic CRUD" section tells you how to insert a row, but the example fails because you have a DATETIME column in your table. So you go to Google and type "php activerecord datetime". You find this forum, you find several people who have the same problem, but no answer. And nothing in the documentation.

And when you manage to find a dirty workaround, you still have to get the last insert id. You click "Docs", you find "insert_id", with the description "Retrieve the insert id of the last model saved". But it doesn't work. It seems related to Connection.php, so I guess I have to get a "connection object", but how? Again, Google, find some people with the same problem, no answer, nothing in the doc, etc. Finally I see a message from an admin who says to use $model->id. It seems to work. But then why is there insert_id() ? What's the difference between the two methods?

There is no real documentation, barely a line of text for each method. You have to guess what is a model, why insert_id is not available from the model class, how to handle different column types (like datetime), etc.

The last stable build is 3 years old. Should I use it or should I use the recent nightly build? No hint. The download page says "You can grab the source code using one of the links below". That's all. No "stable build is recommended in production environnement", nothing in the News section, nothing anywhere.

Activerecord seemed like a cool project at first, but I think it is semi-abandonned. It has been existing for years, but there's no real documentation and no active community. It seems hard, if not impossible, to do basic things like "UPDATE users SET last_seen=NOW () WHERE id=8".

I'm going to try Doctrine. I hope it will be better (it seems to be at the first glance, but I don't know yet). The Doctrine mailing-list got more messages today than this forum in the last two months. And it has a full page explaining how to handle the datetime type.

Guillem CANAL Fri Aug 02 06:16:32 -0400 2013

Hello there,

PHPActiveRecord is really easy to learn but you really need to understand what is a model, in modern PHP development, this is pretty standard stuff :

The CRUD is nothing fancy, really :

Nuita S Fri Aug 09 07:58:05 -0400 2013

If CRUD is nothing fancy, then can you tell me why I can't even read a simple column in my database? I have the last nightly build.

$ echo 'CREATE TABLE `labels` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, name varchar(15) COLLATE utf8_unicode_ci NOT NULL PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' | mysql -utest -ptest test

$ mysql -utest -ptest test
mysql> INSERT INTO `labels` (`id`, `name`) VALUES (NULL, 'العربية');

---------------------- test.php

$connections = array(
'development' => 'mysql://test:/test;charset=utf8',

ActiveRecord\Config::initialize(function($cfg) use ($connections) {

class Label extends \Activerecord\Model {

$l = Label::find(1);
print $l->name;


$ php5 test.php | hexdump -C
00000000 3f 3f 3f 3f 3f 3f 3f |???????|

$ php5 test.php > output.txt
$ file output.txt
output.txt: ASCII text, with no line terminators

Nuita S Fri Aug 09 08:39:23 -0400 2013

I've just found the solution to my problem above. The charset should be specified this way:

$connections = array(
'development' => 'mysql://test:/test?charset=utf8',

with a '?' and not with a ';'

The documentation is wrong, it says to use ';', see

I lost almost one day because of this. This problem has been reported a year ago:
It's time to update the documentation.

EDIT: I updated the wiki.

Guillem CANAL Fri Aug 09 17:06:24 -0400 2013

Curious indeed.

Here's a tip : Unit tests provided with many php libraries give practical examples about how to use components and classes :