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: http://www.ihre-webhosting-domain.de/php/phpinfo.php6)
- 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,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci
AUTO_INCREMENT=1 ;

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';
ActiveRecord\Config::initialize(function($cfg){
$cfg->set_model_directory('model');
$cfg->set_connections(array('development' => 'mysql://user:pass@host/dbname'));
});
$u = User::create(array( 'name' => 'some name', 'emailaddress' => 'some mail'));
$u->save();

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,

Bernhard