php的phalcon框架的db怎样获取mysql执行过程中的错误信息?

phalcon中的数据库操作类PhalconDb,PhalconDbAdapterPdo, PhalconDbAdapterPdoMysql。这几个我看了,都没有数据库执行出错后获取相应错误的方法,不知道是怎么回事,有没有知道的啊?

  1. 假设你已经注册”falsh”服务:
php/** 1. Register the flash service with custom CSS classes */
$di->setflash, function { $flash = new PhalconFlashDirectarray error => alert alert-danger callout callout-danger, success => alert alert-success, notice => alert alert-info, warning => alert alert-warning ; return $flash;
};
  1. 以PhalconMvcModel为例,在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. 当然,你也可以自定义验证信息:
phppublic function validation { $this->validatenew Uniquenessarray field => slug, message => The slug already exists in other articles,please modify the article title ; if $this->validationHasFailed == true { return false; } }

如果是working with models则

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

如果是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; }
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注