An error occurred while using native SQL for UPDATE in Phalcon framework

Source: Internet
Author: User
In the Phalcon framework, when the native SQL statement is used for update operations, a problem occurs: when the content of a field in the database to be operated is blank, the UPDATE will fail? What's going on? Can anyone help me? In the Phalcon framework, when using native SQL statements for update operations,

A problem occurs:
When the content of a field in the database to be operated is null, an error occurs during UPDATE?

What's going on? Can anyone help me?

Reply content:

In the Phalcon framework, when using native SQL statements for update operations,

A problem occurs:
When the content of a field in the database to be operated is null, an error occurs during UPDATE?

What's going on? Can anyone help me?

In this case, the Phalcon ORM will enable several features by default. One of the notNullValidations features is to check whether the field is Not null, so when you do Not fill in the corresponding field, an exception will be thrown.

There are two solutions: Modify the database, and disable this feature. Of course, you can also write the code that automatically complements the default value in the program logic. generally, setting NotNull for a field must be justified. Therefore, it is recommended that the logic of the program be robust, rather than making up for coding errors in other ways.

Document link: 1

Provide the relevant code for reference:

phppublic function skipValidation($skipers=[])    {        foreach ($skipers as $skiper) {            if (empty($this->$skiper)) {                $this->$skiper = new \Phalcon\Db\RawValue('""');            }        }       }

When using:

phppublic function beforeValidation(){  ......     $this->skipValidation(['tag','source_url']);  ......}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.