使用时间时Phalcon Oracle日期时间错误

时间:2017-02-08 10:34:48

标签: oracle datetime phalcon

我的模型中有这个保存方法:

public function save($data = null, $whiteList = null){
    $res = false;
    $sql = '';
    $di = \Phalcon\DI::getDefault();
    try {   
        $param = array("[fecha] = to_date('" . $this->fecha . "', 'YYYY-MM-DD HH24:MI:SS') and [parametro_id] = :parametro_id:",
                        "bind" => array("parametro_id" => $this->parametro_id) );
        $primero = Instantaneos::findFirst($param);
        if ($primero){
            $this->instantaneo_id = $primero->instantaneo_id;
        } else {
            $sql = "select AZUL_S_INSTANTANEOS.nextval from dual";
            $result = $di->getShared('db')->query($sql);
            while($row = $result->fetchArray()){
                $this->instantaneo_id = $row['NEXTVAL'];
            }
        }
        $this->fecha = date('d/M/y', strtotime($this->fecha));
        $res = parent::save($data, $whiteList);
        $res = true;
    } catch (Exception $ex) {
        $res = false;
        $this->appendMessage(new Message($ex->getMessage()));
    }
    return $res;
}

它有效,但是,当我修改这一行时:

$this->fecha = date('d/M/y', strtotime($this->fecha));

有了这个:

$this->fecha = date('d/M/y H:i:s', strtotime($this->fecha));

我收到此错误:

SQLSTATE[HY000]: General error: 1830 OCIStmtExecute: ORA-01830: date format picture ends before converting entire input string

(分机\ PDO_OCI \ oci_statement.c:148) 我需要保存时间信息,我尝试创建自己的save方法,没有parent :: save,在插入或更新时编写自己的sql:

    $sql_i = "insert into AZUL_INSTANTANEOS values(%d,%d,to_date('%s', 'YYYY-MM-DD HH24:MI:SS'),%f,'%s')";
    $sql_u = "update AZUL_INSTANTANEOS set val = %f, valf = '%s' where instantaneo_id = %d";

使用:

$db->execute($sql);

但我得到另一个错误:

Maximum execution time of 30 seconds exceeded in <b>\app\config\services.php</b> on line <b>172</b><br />

我正在使用:

  1. XAMPP 1.8.2(PHP版本5.4.31,Apache / 2.4.10(Win32))
  2. Oracle数据库11g企业版11.2.0.1.0版 - 生产
  3. Phalcon 2.1.0b
  4. ¿任何建议?,thx。

1 个答案:

答案 0 :(得分:1)

Phalcon不完全支持Oracle。位于here的孵化器中有一个驱动程序,您可以使用它。

Oracle也有不同的语法,Phalcon的PHQL可能无法识别。

我建议您首先将SQL语句日志记录添加到您的应用程序中,以便您可以查看发送到数据库的内容,然后找出如何更正它。

查看this页面并向下滚动到apply

所在的位置

添加并查看您的查询内容。