1

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?

1
  • Pedantic note: You should be extending Zend_Db_Table_Abstract Commented Jun 12, 2011 at 16:38

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

ok, i was convinced that i have id as an auto_increment, now it's ok, thanks
0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.