impiix
impiix

Reputation: 46

Problem with zend_db

ZF/PHP This is my class Votes:

class Votes extends Zend_Db_table {

protected $_name = 'votes';

public function vote($object_id, $user_id, $vote){

    $data = array('object_id' => $object_id, 'user_id' => $user_id, 'value' => $vote);
    $this->insert($data);

    return true;

 }
} 

The 'votes' has 'id' primary key. I get: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' when i call vote. Which means the engine every time try to make an insert with '0' as id's value. How to force insert to automatically increment 'id' column?

Upvotes: 1

Views: 150

Answers (3)

Brad Lucas
Brad Lucas

Reputation: 185

The id field in the database should be defined to auto increment.

In MySql the syntax is like the following:

id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT

Upvotes: 0

Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 8856

Make the Vote table id, an auto increment field. This should solve the problem.

Upvotes: 4

Shaun Hare
Shaun Hare

Reputation: 3871

Do not add the id - ensure the field type in the database is set to auto-increment and also set it as primary key using

 protected $_primary

Upvotes: 0

Related Questions