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

Asked

Viewed 227 times

1

I need to update a field (office) of a table (investor) of the database (B2c) on my website. However, this UPDATE will depend on a SELECT query that is made in another database of another site (both sites belong to the same company). Both banks are in Mysql.

Below the code I 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 putting Zero values. There are cases where inside this table uh does not have P or C values (office = 0). It may be that I have only O or only A, and then I would need to update by putting 1 or 2 respectively.

What could be wrong? I’m not sure if he was able to connect to my db2 bank (from the other site). The config.INI file had the addition of database_portal data. Here is the code of this file (I omitted some information here for security and put below between << and >> ):

[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 there’s also libBanco.php, included inside the trunk/libs/libBanco directory. In this file only includes the SWITCH function related to the other site’s database (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 don’t know if any settings were missing in this case either. What might be? I hope it’s just some bug in the code I initially implemented.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.