1

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(count($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;
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Future King
  • 3,819
  • 6
  • 28
  • 37

1 Answers1

-1

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.

Abel Mohler
  • 785
  • 5
  • 12