【问题标题】:Insert array into postgresql error将数组插入postgresql错误
【发布时间】:2016-11-04 11:16:07
【问题描述】:

我使用 Phalcon 框架和 PostgreSQL

我尝试向数据库列类型插入一个数组:varchar[]:

array(4) { [0]=> string(1) "1" [1]=> string(1) "6" [2]=> string(1) "9" [3]=> string(2) "12" }

但出现以下错误:

SQLSTATE[HY093]:参数号无效:参数未定义

请帮我解决这个问题

【问题讨论】:

  • 请分享您的代码。如果没有更多上下文,就不可能为您提供帮助。
  • 向我们展示您的查询代码
  • 不确定该代码应该是什么,但在 Postgres 中您需要像这样指定数组:array['1', '6', '9', '12']

标签: postgresql phalcon


【解决方案1】:

这是我的模型:

<?php
namespace App\Models;

use Phalcon\Mvc\Model;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Uniqueness;

class Document extends Model
{

    public $id;
    public $relatedocument;

    public function getSource()
    {
        return "document";
    }

=====表格======

<?php
namespace App\Modules\Backend\Forms;

use Idoc\Models\Document;
use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Select;

class DocumentForm extends Form
{
    public function initialize($entity = null, $options = null)
    {
        $data = Document::find();
        $this->add(new Select('relatedocument[]', $data, [
            'using' => [
                'id',
                'name'
            ],
            'useEmpty'  => true,
            'emptyText' => '....',
            'multiple' => 'multiple', 
            'class' => 'form-control search-select'
        ]));
     }

=====addAction======

public function addAction()
    {
        if ($this->request->isPost()) { 
            $doc = new Document();
            $doc->relatedocument = $this->request->getPost('relatedocument');
            if (!$doc->save()) {
            $this->flash->error($doc->getMessages());
            } else {
                $this->flash->success("Văn bản đã được tạo");
                Tag::resetInput();
            }    
        }
        $this->view->form = new DocumentForm(null);
    }

【讨论】:

  • update your question 而不是发布答案。按问题下方的edit 按钮。
  • 在您的表单中,您将元素命名为 relatedocument[],但在您的控制器中,您请求的是 relatedocument
猜你喜欢
  • 2017-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-29
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多