Bernhard Streit Sat Jan 29 04:03:24 -0500 2011

Subject: Troubles getting started

Hey there,

trying to get php.activerecord running with a simple example, but it doesn't work.

My (hosters') config:
- PHP 6 (more infos:
- mySQL: "SELECT VERSION" returns "5.0.91-log"

My table:

CREATE TABLE `users` (  
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(50) collate latin1_german2_ci NOT NULL,
`emailaddress` varchar(100) collate latin1_german2_ci NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci

My "User" class:

class User extends ActiveRecord\Model
public $name;
public $emailaddress;

My index.php6 file:

require_once 'activerecord/ActiveRecord.php';
require_once 'model/User.php';
$cfg->set_connections(array('development' => 'mysql://user:pass@host/dbname'));
$u = User::create(array( 'name' => 'some name', 'emailaddress' => 'some mail'));

The user, pass, host and dbname placeholders I have replaced with the ones of my local installation.

When I run this, I get the following error:

Fatal error:  Uncaught exception 'ActiveRecord\DatabaseException' with 
message '42S22, 1054, Unknown column '' in 'field list''
in PATH/activerecord/lib/Connection.php:276
Stack trace:
#0 PATH/activerecord/lib/Table.php(317):
ActiveRecord\Connection->query('INSERT INTO `us...', Array)
#1 PATH/activerecord/lib/Model.php(803): ActiveRecord\Table->insert(Array)
#2 PATH/activerecord/lib/Model.php(758): ActiveRecord\Model->insert(true)
#3 PATH/activerecord/lib/Model.php(739): ActiveRecord\Model->save(true)
#4 PATH/index.php6(23): ActiveRecord\Model::create(Array)
#5 {main}
thrown in PATH/activerecord/lib/Connection.php on line 276

(I've replaced the long path of my hosters system by placeholder PATH in the stacktrace).

Does anyone know why I'm getting this error? Why is there an empty string in the field list?

Is there a way to get the complete sql code that was used for the insert, instead of the truncated one?

Many thanks in advance,


Taylor Otwell Mon Jan 31 12:25:04 -0500 2011

You don't have to explicitly declare your properties in your model. Remove your two property definitions and see if it works.

Kien La Fri Feb 04 17:23:56 -0500 2011

We don't currently support PHP6.

Bernhard Streit Sun Feb 06 06:07:52 -0500 2011

Hey guys,

thanks for your replies!

@Taylor: When I remove the properties from the model, I get the following error:

Uncaught exception 'ActiveRecord\UndefinedPropertyException' with message '
Undefined property: User->name in [...]/activerecord/lib/Model.php on line 428
Undefined property: User->emailaddress in [...]/activerecord/lib/Model.php on line 428
' in [...]/activerecord/lib/Model.php:1066

Stack trace:
#0 [...]/activerecord/lib/Model.php(357): ActiveRecord\Model->set_attributes_via_mass_assignment(Array, true)
#1 [...]/activerecord/lib/Model.php(738): ActiveRecord\Model->__construct(Array)
#2 [...]/index.php6(23): ActiveRecord\Model::create(Array)
#3 {main}
thrown in [...]/activerecord/lib/Model.php on line 1066

@Kien: That's really a pity, my hoster only offers me PHP 5.2 and 6 :(