本文介绍了Heroku连接CakePHP v3.0.12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据保存到Heroku Postgres,Heroku也使用它与Salesforce连接。



错误:[b]

 错误:[PDOException] SQLSTATE [42883]:未定义函数:7 
错误:函数get_xmlbinary()不存在
LINE 1:SELECT(get_xmlbinary()='base64')

提示:否函数匹配给定的名称和参数类型。
您可能需要添加明确的类型转换。
$ b $ QUERY:SELECT(get_xmlbinary()='base64')
CONTEXT:PL / pgSQL函数hc_contact_status()第3行在
IF请求URL:/注册

并且它的堆栈跟踪是

 #0 app / vendor / cakephp / cakephp / src / Database / Statement / StatementDecorator.php(169):PDOStatement-> execute(NULL)
#1 app / vendor / cakephp / cakephp / src /Database/Connection.php(274):Cake \Database\Statement\StatementDecorator-> execute()
#2 app / vendor / cakephp / cakephp / src / Database / Query.php(176) :Cake \ Database \Connection-> run(Object(Cake \\\\\\\\\\\\\))
#3 app / vendor / cakephp / cakephp / src / ORM / Table.php(1516):Cake \Database\Query-> execute()
#4 app / vendor / cakephp / cakephp / src / ORM / Table.php(1436):Cake\ORM\Table-> _insert(Object (App_\\Model\\Entity\Contact),Array)
#5 app / vendor / cakephp / cakephp / src / ORM / Table.php(1367):Cake\ORM\Table-> _p rocessSave(Object(App\Model\Entity\Contact),Object(ArrayObject))
#6 app / vendor / cakephp / cakephp / src / Database / Connection.php(561):Cake\ORM \表格 - > Cake \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ):Cake \Database\Connection-> transactional(Object(Closure))
#8 app / src / Controller / ContactController.php(126):Cake\ORM\Table-> save( Object(App\Model\\Entity\Contact))
#9 [内部函数]:App\Controller\ContactController->注册('注册')
#10应用程序/供应商/cakephp/cakephp/src/Controller/Controller.php(412):call_user_func_array(Array,Array)
#11 /app/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(114):Cake \\ \\ Controller \Controller-> invokeAction()
#12 app / vendor / cakephp / cakephp / src / Routing / Dispatcher.php(87):Cake\Routing\Dispatcher-> _invoke(Object App\Controller\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\' \Response))
#14 {main}

我的app.php中的数据库块是

 'Datasources'=> [
'default'=> [
'className'=> 'Cake \Database\Connection',
'driver'=> 'Cake \Database\Driver\Postgres',
'persistent'=>假,
'host'=> '[heroku postgre的主机名]',
'port'=> '5432',
'username'=> '[heroku postgre的用户名]',
'password'=> '[heroku postgre的密码]',
'database'=> '[heroku postgre的数据库]',
'encoding'=> 'utf8',
'timezone'=> 'UTC',
'schema'=> 'salesforce',
'cacheMetadata'=>假,
'log'=>假,
'quoteIdentifiers'=> false,
],

在此设置中,我可以从Heroku连接中检索数据,我试图用DB写东西,它会返回上面显示的错误。



我找到了一个为Lavera用户制作的Q和A,我想我也有同样的情况。



我认为Schema =>'salseforce'需要'公开'
,但我不知道如何更改CakePHP环境中的设置。

我也跑了

 #set search_path = salesforce,public ; 

如果有人知道CakePHP的解决方案,请告诉我。
我感谢您的帮助



更新:



我得到了Heroku支持的响应,他们给了我解决这个问题的一个好主意。



以下是heroku的回应和提示

为什么会发生这种情况?

 此错误通常是应用程序错误地设置
search_path并忽略公共架构的结果。运行set search_path
salesforce,psql中的public只为当前会话设置它。

如何解决这个问题?

 数据源:default:schema => 'public'而不是salesforce,然后
在应用程序的其他地方使用完全限定的表名。

 你可以设置schema => 'salesforce,public'

请注意,他对CakePHP环境并不专业,所以他不确定如果第二种方法有效或没有。

但我想我可以做第一种方法。



如果您对此有更多的了解或想分享这个话题,请在下面留言

解决方案

[其他更新&解决方案]



我刚刚尝试了heroku支持的说法。
我编辑了一个模型中的构造函数,如下面的
(在我的例子中,我没有联系模型)

$ p $ public function initialize(array $ config)
{
parent :: initialize($ config);
//为以下表名添加salesforce
$ this-> table('salesforce.account');
$ this-> displayField('name');
$ this-> primaryKey('id');





在app.php文件中

 'schema'=> 'public',

模式指向公共。



这有效!


I am trying to save data to Heroku Postgres which is also using for heroku connect with Salesforce.

I have an error that says

 Error:  [PDOException] SQLSTATE[42883]: Undefined function: 7
 ERROR:  function   get_xmlbinary() does not exist
 LINE 1: SELECT (get_xmlbinary() = 'base64')

 HINT:   No function matches the given name and argument types.
         You might need to add explicit type casts.

 QUERY:  SELECT (get_xmlbinary() = 'base64')
 CONTEXT: PL/pgSQL function hc_contact_status() line 3 at
          IF Request URL: /signup

and it's stack trace is

 #0 app/vendor/cakephp/cakephp/src/Database/Statement/StatementDecorator.php(169): PDOStatement->execute(NULL)
 #1 app/vendor/cakephp/cakephp/src/Database/Connection.php(274): Cake\Database\Statement\StatementDecorator->execute()
 #2 app/vendor/cakephp/cakephp/src/Database/Query.php(176): Cake\Database\Connection->run(Object(Cake\ORM\Query))
 #3 app/vendor/cakephp/cakephp/src/ORM/Table.php(1516): Cake\Database\Query->execute()
 #4 app/vendor/cakephp/cakephp/src/ORM/Table.php(1436): Cake\ORM\Table->_insert(Object(App\Model\Entity\Contact), Array)
 #5 app/vendor/cakephp/cakephp/src/ORM/Table.php(1367): Cake\ORM\Table->_processSave(Object(App\Model\Entity\Contact), Object(ArrayObject))
 #6 app/vendor/cakephp/cakephp/src/Database/Connection.php(561): Cake\ORM\Table->Cake\ORM\{closure}(Object(Cake\Database\Connection))
 #7 app/vendor/cakephp/cakephp/src/ORM/Table.php(1368): Cake\Database\Connection->transactional(Object(Closure))
 #8 app/src/Controller/ContactController.php(126): Cake\ORM\Table->save(Object(App\Model\Entity\Contact))
 #9 [internal function]: App\Controller\ContactController->signup('signup')
 #10 app/vendor/cakephp/cakephp/src/Controller/Controller.php(412): call_user_func_array(Array, Array)
 #11 /app/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(114): Cake\Controller\Controller->invokeAction()
 #12 app/vendor/cakephp/cakephp/src/Routing/Dispatcher.php(87): Cake\Routing\Dispatcher->_invoke(Object(App\Controller\ContactController))
 #13 app/webroot/index.php(37): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
 #14 {main}

Database block in my app.php is

'Datasources' => [
    'default' => [
        'className'  => 'Cake\Database\Connection',
        'driver'     => 'Cake\Database\Driver\Postgres',
        'persistent' => false,
        'host'       => '[ host name for the heroku postgre ]',
        'port'       => '5432',
        'username'   => '[ user name for the heroku postgre ]',
        'password'   => '[ password for the heroku postgre ]',
        'database'   => '[ database for the heroku postgre ]',
        'encoding'   => 'utf8',
        'timezone'   => 'UTC',
        'schema'     => 'salesforce',
        'cacheMetadata' => false,
        'log'        => false,
        'quoteIdentifiers' => false,
    ],

In this setting, I can retrieve data from Heroku connect but when I try to write something in DB, it will return the error I showed above.

I found an Q and A made for Lavera user and I think I have the same situation.https://discussion.heroku.com/t/heroku-connect-with-laravel/1335

I think Schema => 'salseforce' need to be 'public'but I don't know how to change the setting in CakePHP environment.

I have also run

# set search_path=salesforce, public;

If anybody knows a solution for the CakePHP, Please let me know.I appreciate your help

Update:

I got respond from Heroku support and they gave me a good idea to solve this question.

Following are heroku's respond and tip

Why this happened ?

    this error is usually a result of an application incorrectly setting
 search_path and ignoring the public schema. Running set search_path
 salesforce,public in psql only sets it for the current session.

How to possibly resolve this question ?

   Datasources:default:schema => 'public' rather than salesforce and then
use fully qualified table names elsewhere in your application.

or

    you could set schema => 'salesforce,public'

Note that he wasn't professional for CakePHP environment so He doesn't sure if second method works or not.

but I think I can do the first method.

If you have more idea of it or something to share on this topic please comment on below

解决方案

[Additional Update & Solution]

I just tried what the heroku support said.I edited a constructor in a Model like following(in my case, I did contact model )

public function initialize(array $config)
{
    parent::initialize($config);
    // added "salesforce" for following table name
    $this->table('salesforce.account');
    $this->displayField('name');
    $this->primaryKey('id');

}

andIn the app.php file

'schema'     => 'public',

Schema points to public.

This worked!

这篇关于Heroku连接CakePHP v3.0.12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 08:19