Making MySQL UPDATE in database DB according to MySQL SELECT in DB2 database

1

I need to do UPDATE in an (office) field of a database (investor) database (b2c) on my site. However, this UPDATE will depend on a SELECT query that is made in another database from another site (both sites belong to the same company). The two banks are in MySQL.

Below the code I've implemented:

    $emailInv = $this->email;
    $sqlNuevo = "SELECT DISTINCT uh.TIPO_INVESTIDOR FROM ipi_tst.uh
                JOIN ipi_tst.investidor i ON i.ID = uh.ID_INVESTIDOR
                JOIN ipi_tst.usuario u ON u.ID = i.ID_USUARIO
                WHERE u.EMAIL = '$emailInv' AND u.ID <> 0 ORDER BY FIELD(TIPO_INVESTIDOR,'P','C','O','A')";
    $rNew = System::element('db2')->query($sqlNuevo);
    if ($rNew[0]['TIPO_INVESTIDOR'] == 'O'){
        $sqlUpd = "UPDATE b2c.investidor SET office = '1' WHERE email = '$emailInv' AND ID <> 0";
        $res = System::element('db')->query($sqlUpd);
    }
    else if ($rNew[0]['TIPO_INVESTIDOR'] == 'A'){
        $sqlUpd = "UPDATE b2c.investidor SET office = '2' WHERE email = '$emailInv' AND ID <> 0";
        $res = System::element('db')->query($sqlUpd);
    }
    else {
        $sqlUpd = "UPDATE b2c.investidor SET office = '0' WHERE email = '$emailInv' AND ID <> 0";
        $res = System::element('db')->query($sqlUpd);
    }

For now, it can only update by placing Zero values. There are cases where within this table uh does not have P or C values (office = 0). It may be that I have only O or just A, and then I would need to update by setting 1 or 2, respectively.

What could be wrong? I'm not sure if he was able to make the connection to my DB2 bank (from another site). The config.ini file had the addition of database_portal data. Here is the code for this file (I've omitted some information here for security and I've placed it below ):

[application]
versao = 1.0
titulo = B2C
default_pagina = index
default_metodo = index
default_erro = erro
default_erro_403 = erro403
default_erro_404 = erro404
default_login = login
debug = 0
idioma = pt-BR
moeda = RS
identificador = ipi_

[mensagem]
fundo = #000000
cor = #ffffff
delay = 2000
posicao = bottom

[dir]
raiz[localhost] = http://localhost/
raiz[<<MEU IP DO SITE>>] = <<MEU IP DO SITE>>
raiz[<<MEU LINK DO SITE>>] = <<MEU LINK DO SITE>>

[database]
db_alias = db
db_type = mysql
db_name = b2c
db_hostname = localhost
db_username = <<LOGIN DO db>>
db_password = <<SENHA DO db>>
db_port = 3306

[database_portal]
db_alias = db2
db_type = mysql
db_name = ipi_tst
db_hostname = <<IP DO OUTRO SITE>>
db_username = ipi_tst
db_password = ipi_tst
db_port = 3306

[cookie]
duracao = 10800
caminho = /
dominio = 

[mail]
mailer_type = system
admin_email = [email protected]
admin_name = "Admin - Framework"
smtp_server = mail.framework.com 
smtp_port = 25;
x_mailer = "xxxxx"
smtp_server = "mail.framework.com"
smtp_port = 25
smtp_timeout = 30

[logging]
nivel_log = 200
handler_log = file
arquivo_log = erros.log

[document_root]
root = <<DIRETÓRIO RAIZ>>
rootDSV = <<OUTRO DIRETÓRIO>>

[version]
atual_version = 1.5

And also has libBanco.php, included inside the trunk / libs / libBanco directory. This file only includes the SWITCH function related to the bank of the other site (db2 or database_portal):

<?php
$dir = '../libs/libBanco'; 

require_once("$dir/banco.php");
require_once("$dir/modeloBanco.php");

switch(Config::retorna('database', 'db_type')) {
    case 'oracle':
        require_once('oracle.php');
        $db = new Oracle();            
        break;
    case 'mysql':
        require_once('mysql.php');
        $db = new Mysql();            
        break;            
    default:
        $db = null;
        break;
}

switch(Config::retorna('database_portal', 'db_type')) {
    case 'oracle':
        require_once('oracle.php');
        $db2 = new Oracle();
        break;
    case 'mysql':
        require_once('mysql.php');
        $db2 = new Mysql();
        break;
    default:
        $db2 = null;
        break;
}

System::define(Config::retorna('database', 'db_alias'), $db);
System::define(Config::retorna('database_portal', 'db_alias'), $db2);
?>

I do not know if any configuration was missing in this case either. What can it be? I hope it is just some error in the sqlNew of the code that I initially implemented.

    
asked by anonymous 26.08.2015 / 20:47

0 answers