Doctrine CodeIgniter MySQL CRUD errors

Posted by 01010011 on Stack Overflow See other posts from Stack Overflow or by 01010011
Published on 2010-04-23T22:02:08Z Indexed on 2010/04/23 22:03 UTC
Read the original article Hit count: 449

Filed under:
|
|
|

Hi, I am using CI + Doctrine + MySQL and I am getting the following CRUD errors:

(1) When trying to create a new record in the database with this code:

$book_title = 'The Peloponnesian War';
$b = new Book();
$b->title = $book_title;
$b->price = 10.50;
$b->save();

I get this error:

Fatal error: Uncaught exeption 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'field list' in ...

(2) When trying to fetch a record from the database and display on my view page with this code:

$book_title = 'The Peloponnesian War';
$title = $book_title;
$search_results = Doctrine::getTable('Book')->findOneByTitle($title);
echo $search_results->title; (in view file)

I get this error:

Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[45S22]: Column not found: 1054 Unknown column 'b.id' in 'field list" in ...

And finally, when I try to update a record as follows:

$book_title = 'The Peloponnesian War';
$title = $book_title;
$u = Doctrine::getTable('Book')->find($title);
$u->title = $title;
$u->save();

I get a similar error:

Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'b.id' in 'field list''in ...

Here is my Doctrine_Record model:

class Book extends Doctrine_Record{
    public function setTableDefinition()
    {
       $this->hasColumn('book_id');
       $this->hasColumn('isbn10','varchar',20);
       $this->hasColumn('isbn13','varchar',20);
       $this->hasColumn('title','varchar',100);
       $this->hasColumn('edition','varchar',20);
       $this->hasColumn('author_f_name','varchar',20);
       $this->hasColumn('author_m_name','varchar',20);
       $this->hasColumn('author_l_name','varchar',20);
       $this->hasColumn('cond','enum',null, array('values' => array('as new','very      good','good','fair','poor')));
       $this->hasColumn('price','decimal',8, array('scale' =>2));
       $this->hasColumn('genre','varchar',20);
    }
    public function setUp()
    {
       $this->setTableName('Book');
       //$this->actAs('Timestampable');
    }

Any assistance will be really appreciated. Thanks in advance.

© Stack Overflow or respective owner

Related posts about doctrine

Related posts about codeigniter