Postgresql 使用来自其他数据库的变量执行函数

Postgresql 使用来自其他数据库的变量执行函数,postgresql,cakephp,mariadb,cakephp-4.x,Postgresql,Cakephp,Mariadb,Cakephp 4.x,我试图用其他数据库中的值执行一个函数 我正在使用框架cakephp4.x和2db、Postgresql和MariaDB 在Controller/Programscontroller.php中: use Cake\Datasource\ConnectionManager; public function pro() { $connection = ConnectionManager::get('default');// Postgresql,in this one i have my fu

我试图用其他数据库中的值执行一个函数

我正在使用框架cakephp4.x和2db、Postgresql和MariaDB

在Controller/Programscontroller.php中:

use Cake\Datasource\ConnectionManager;

public function pro()
{    $connection = ConnectionManager::get('default');// Postgresql,in this one i have my function test(character varying,bigint,bigint)
     $connection2 = ConnectionManager::get('test');// MariaDB, in this one i want some variables
     $data = $connection2->execute('SELECT stuffs from stuff'); //My $data i want
      foreach ($data as $data) //I declare here 3 variables, to save some $data
    {  $w1=$data['cod_item']; 
       $w2=$data['fecha_solicitud_pago'];
       $w3=$data['monto_total'];
       $connection->execute('SELECT test(w1,w2,w3)');//here is my problem
      }    
}
我执行并出现错误SQLSTATE[42703]:未定义的第7列,不存在的第w1列。如何正确地定义我的3个变量w1、w2、w3,并在其他数据库的函数中使用它们。

我发现了两个问题:

1.
$connection->execute('selecttest(w1,w2,w3)')未使用php变量。它应该是:

$connection->execute("SELECT test($w1,$w2,$w3)");
请注意,必须使用双引号才能在字符串中使用变量

2.您必须以正确的形式使用函数。如果函数收到(文本、日期、数字),则必须相应地发送:

$connection->execute("SELECT test('$w1','$w2',$w3)");
// or, for more accuracy
$connection->execute("SELECT test('$w1'::text,'$w2'::date,$w3)");
当您执行
$connection->execute()
时,您正在执行一条SQL语句,因此必须编写良好。上述示例在POSTGRESQL中解释为:

SELECT test('asbd'::text,'2020-02-05'::date,39021)
假设php变量具有这些值