• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 4年前 (2022-01-25) 20次浏览 已收录 0个评论
文章目录[隐藏]

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

回复内容:

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

  1. 假设你已经注册”falsh”服务:
<code>php</code><code>/** 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;});</code>
  1. 以\Phalcon\Mvc\Model为例,在controller里面:
<code>php</code><code>if ($Article->save()) {                        $this->flash->success($Article->title . 'has been updated');                    } else {                        foreach ($Article->getMessages() as $message) {                  <strong>2本文来源gaodaima#com搞(代@码$网6</strong><pre>搞gaodaima代码

$this->flashSession->error($message); } return $this->response->redirect($paginateUrl); $this->view->disable(); }

  1. 当然,你也可以自定义验证信息:
<code>php</code><code>public 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;      }    }</code>

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

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

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php的phalcon框架的db怎样获取mysql执行过程中的错误信息?
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址