I think it would be better to write own DQL (or raw SQL query if you know...) with part ON DUPLICATE KEY update... Something like
http://stackoverflow.com/a/24384768 And you can save on SQL query :)
Bump: I understand the problem now... You can write small query for check if given IP and user exist in database, because there is unique key...
PHP Code:
/**
* Ajout d'une IP
*/
public function executeAjouterip(sfWebRequest $r) {
if (!filter_var($r->getPostParameter("adresseip"), FILTER_VALIDATE_IP)) {
$this->getUser()->setFlash("error", $this->getContext()->getI18N()->__("Invalid IP address."));
$this->redirect("membres/options");
}
$exists = Doctrine_Query::create()
->select('mid')
->from('Ip')
->where("mid = ?", $this->getUser()->getAttribute("id"))
->andWhere('ip = ?', inet_pton($r->getPostParameter("adresseip")))
->execute();
if ($exists) {
$this->getUser()->setFlash("notice", $this->getContext()->getI18N()->__("Your IP exists in database!"));
$this->redirect("membres/options");
}
// On ajoute la nouvelle IP
$ip = new Ip();
$ip->setIp(inet_pton($r->getPostParameter("adresseip")));
$ip->setMid($this->getUser()->getAttribute("id"));
$ip->setCreation(date("Y-m-d H:i:s"));
$ip->setLastconnect(date("Y-m-d H:i:s"));
$ip->save();
$this->getUser()->setFlash("notice", $this->getContext()->getI18N()->__("Your IP address has been added !"));
$this->redirect("membres/options");
}
Maybe you need little fix this small code, because i don't know the complete structure. But i hope it helps ;)