First time using ORM. I just want a 'hello world' to demo finding some records from MySQL with FuelPHP 1.4.
My fuel_test database table called 'users' looks like this:
id (int) | name (varchar) | description (varchar) | company (varchar)
My database config:
'default' => array(
'connection' => array(
'dsn' => 'mysql:host=localhost;dbname=fuel_test',
'username' => 'fuel',
'password' => 'fuel',
),
),
My ORM model:
class Model_User extends Orm\Model
{
protected static $_table_name = 'users';
protected static $_primary_key = array('id');
protected static $_properties = array(
'id',
'name',
'description',
'company'
);
}
The database connection works fine if I just use the database class:
$query = DB::query('SELECT * FROM Users');
$result = $query->execute();
I tried to use the ORM class like this:
$entry = Model_User::find('first');
But I get this error:
Fuel\Core\Database_Exception [ 42000 ]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '."id" AS "t0_c0", "t0"."name" AS "t0_c1", "t0"."description" AS "t0_c2", "t0"."c' at line 1 with query: "SELECT "t0"."id" AS "t0_c0", "t0"."name" AS "t0_c1", "t0"."description" AS "t0_c2", "t0"."company" AS "t0_c3" FROM "users" AS "t0" ORDER BY "t0"."id" ASC LIMIT 1"
What am I doing wrong?
Is there a way to view the SQL statements called by ORM class to assist debugging?