How does the db of php phalcon framework obtain the error message during mysql execution?

Source: Internet
Author: User
PhalconDb, PhalconDbAdapterPdo, and PhalconDbAdapterPdoMysql are database operations in phalcon. I have read these questions and I have not found any methods for obtaining the corresponding errors after database execution errors. I don't know what is going on. Do you know? Phalcon \ Db, Phalcon \ Db \ Adapter \ Pdo, Phalcon \ Db \ Adapter \ Mysql in Phalcon. I have read these questions and I have not found any methods for obtaining the corresponding errors after database execution errors. I don't know what is going on. Do you know?

Reply content:

Phalcon \ Db, Phalcon \ Db \ Adapter \ Pdo, Phalcon \ Db \ Adapter \ Mysql in Phalcon. I have read these questions and I have not found any methods for obtaining the corresponding errors after database execution errors. I don't know what is going on. Do you know?

  1. Assume that you have registered the "falsh" service:
php/** 1. Register the flash service with custom CSS classes */$di->set('flash', function() {    $flash = new \Phalcon\Flash\Direct(array(        'error'   => 'alert alert-danger callout callout-danger',        'success' => 'alert alert-success',        'notice'  => 'alert alert-info',        'warning' => 'alert alert-warning'    ));    return $flash;});
  1. Take \ Phalcon \ Mvc \ Model as an example. In the controller:
phpif ($Article->save()) {                        $this->flash->success($Article->title . 'has been updated');                    } else {                        foreach ($Article->getMessages() as $message) {                            $this->flashSession->error($message);                        }                        return $this->response->redirect($paginateUrl);                        $this->view->disable();                    }
  1. Of course, you can also customize the verification information:
phppublic function validation()    {      $this->validate(new Uniqueness(array(          'field' => 'slug',          'message' => 'The slug already exists in other articles,please modify the article title'      )));      if ($this->validationHasFailed() == true) {          return false;      }    }

For working with models

$robot       = new Robots();$robot->type = "mechanical";$robot->name = "Astro Boy";$robot->year = 1952;if ($robot->save() == false) {    echo "Umh, We can't store robots right now: \n";    foreach ($robot->getMessages() as $message) {        echo $message, "\n";    }} else {    echo "Great, a new robot was saved successfully!";}

For phql

$phql   = "INSERT INTO Cars VALUES (NULL, 'Nissan Versa', 7, 9999.00, 2012, 'Sedan')";$result = $manager->executeQuery($phql);if ($result->success() == false){    foreach ($result->getMessages() as $message)    {        echo $message->getMessage();    }}

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.