Integrity constraint violation: 1048 Column 'url_id' cannot be null
I am getting this error in Zend Framework: Integrity constraint violation: 1048 Column 'url_id' cannot be null
My code is:
$stmt = $this->select()->where('url_address = ?', $url_address)->query();
$r = $stmt->fetchAll();
print_r($r);
if(coun开发者_StackOverflowt($r)==0){
$data = array(
'url_address' => $url_address,
);
$this->insert($data);
$stmt = $this->select()->where('url_address = ?', $url_address)->query();
$r = $stmt->fetchAll();
}
echo $r->url_id;
return $r->url_id;
That's a MySQL error, not really a PHP one. You need the url_id field to be a default value of NULL if nothing is going to be inserted there.
精彩评论