This topic is locked

second connection on view

10/28/2020 4:31:20 AM
PHPRunner General questions
ffrinai author

Hi,

i have 2 connections,

in the primary connection i have a table

registro
in the second connection i have 2 tables

dipendenti

strutture

and the custom view dipendenti_vista on the 2 tables dipendenti and strutture:
SELECT

dipendenti.matricola,

dipendenti.cognome,

dipendenti.nome,

dipendenti.data_assunzione,

dipendenti.data_fine_rapporto,

COALESCE(dipendenti.email, 'zz') as email,

dipendenti.codice_centro_di_costo,

strutture.desc_cc

FROM dipendenti

INNER JOIN strutture ON dipendenti.codice_centro_di_costo = strutture.codice_cc
in import page before insert record of registro if i use:
// switch connection to 2nd connetion

DB::SetConnection("2ndconnection");

// execute query
$rs = DB::Query("select from dipendenti where email='".$values['email']."'");

$data1=$rs->fetchAssoc();

if($data1['codice_centro_di_costo']!=null)

{

$values['cdc']=$data1['codice_centro_di_costo'];

$rs2 = DB::Query("select
from strutture where codice_cc='".$values['cdc']."'");

$data2=$rs2->fetchAssoc();

$values['cdc_desc']=$data2['desc_cc'];

}
// switch back to primary connection

DB::SetConnection("");
it works fine, but i must execute 2 queryes
then i try with the custom view to use only one query
// switch connection to 2nd connetion

DB::SetConnection("2ndconnection");

// execute query
$rs = DB::Query("select * from dipendenti_vista where email='".$values['email']."'");

$data1=$rs->fetchAssoc();

if($data1['codice_centro_di_costo']!=null)

{

$values['cdc']=$data1['codice_centro_di_costo'];

$values['cdc_desc']=$data1['desc_cc'];

}
// switch back to primary connection

DB::SetConnection("");
i have the error:

Fatal error: Call to a member function fetchAssoc() on a non-object in the line -> $data1=$rs->fetchAssoc();
i also tried to remove the line DB::SetConnection("2ndconnection"); to work in the primary connection

but the fatal error remain.
is there a solution to use the custom view instead the two queryes?

thanks

Fabio
phprunner enterprise 10.3 build 34865

mariadb 10

Sergey Kornilov admin 10/28/2020

I'm not 100% sure I understand the question, but if you are trying to build a custom view that uses two different database connections - this is not possible.

ffrinai author 10/29/2020



I'm not 100% sure I understand the question, but if you are trying to build a custom view that uses two different database connections - this is not possible.


the custom view use 2 tables of secondary connection