-1

how can try insert a record on data/mydatabase.db a new record. i'm using zend framework 2 and apiligity for insert a new record on my db now i can get all records but i can't insert have this for insert

     public function create($data)
        { $sql = new Sql($this->adapter);
            $insert = $sql->insert('album');
            $newData = array(
                    'id'        => $data->id,
                    'artist'    => $data->artist,
                    'title'     => $data->title
            );
            $insert->values($newData);
            $selectString = $sql->getSqlStringForSqlObject($insert);
            $results = $this->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE); 
}

have a error error here

how insert a new record? thanks

BlackHack123
  • 349
  • 1
  • 10
  • 1
    Value for collumn "id" needs to be unique, you are trying to insert duplicated value. – Adam Jan 15 '16 at 04:28

1 Answers1

2

This is a database error : Integrity constraint violation: UNIQUE constraint failed: album.id.

If you use an ID that haven't been used, your code should work properly.

Basically this means that you successfully asked the database to store your data but he/she politely refused to store it based on his/her configuration.

Clément Prévost
  • 8,000
  • 2
  • 36
  • 51