Last active
January 21, 2022 21:35
-
-
Save boliveirasilva/dbf22d509b972f0b06bb33f2d27c3446 to your computer and use it in GitHub Desktop.
Exemplos de utilização ADODB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Quando for trocar o modo de Fetch, salve a configuração antiga para restaurar depois. | |
// Não tem como garantir que ela estará configurada como ADODB_FETCH_NUM. | |
$old_fetch_mode = $this->Db->SetFetchMode(ADODB_FETCH_ASSOC); | |
// O getArray que você usou seria +/- isso | |
$ar = $this->Db->getAll("SELECT * FROM ACT"); | |
# Abaixo é um exemplo de insert, compatível para fire e oracle. | |
// Aqui eu uso um generator/sequencer para pegar o próximo ID. | |
$this->integration_id = $this->Db->GenID('SQ_LOG_INTEGRACAO'); | |
// Seleciono um registro em branco mesmo, só para a biblioteca fazer a leitura de configurações de colunas | |
$empty_msg_retorno = $this->Db->Execute('SELECT * FROM TB_LOG_MSG_RETORNO WHERE LOG_ID = -1'); | |
foreach ($messages as $message) { | |
$insertData = array( // O array associativo com os dados que quero inserir. | |
'LOG_ID' => $this->integration_id, | |
'TP_RETORNO' => $message['TP_RETORNO'], | |
'COD_MENSAGEM' => $message['COD_MENSAGEM'], | |
'NUM_REGISTRO' => $message['NUM_REGISTRO'], | |
'DEC_MENSAGEM' => $message['DEC_MENSAGEM'], | |
); | |
$sql = $this->Db->GetInsertSQL($empty_msg_retorno, $insertData); // gera string de 'INSERT' no formato do banco destino. | |
$this->Db->Execute($sql); | |
} | |
$this->Db->SetFetchMode($old_fetch_mode); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* -[ CONEXÃO COM O BANCO ]- */ | |
// Se as informações estiverem separadinhas, o código abaixo consegue conectar com qualquer banco. | |
// Mas caso host/db_name estejam concatenados, o Fire utiliza essa mistura no primeio parâmetro do | |
// _Connect_ e o Oracle utiliza no quarto parâmetro. | |
$conn = ADONewConnection($driver); | |
$conn->Connect($db_host, $db_user, $db_pass, $db_name); | |
if (!$conn) throw new SerconServiceException('Não foi possível se conectar ao banco.'); | |
/* -[ SALVAR DADOS BLOB ]- */ | |
// Antigamente para salvar um blob no banco era preciso primeiro converter utilizando o blobEncode() | |
// Mas agora basta chamar o método updateBlob() e passar os dados diretamente. | |
// $blob = $this->Db->blobEncode($data); /* Não há mais necessidade de realizar esta conversão. */ | |
$this->Db->updateBlob('TB_LOG_INTEGRACAO', $column, $data, 'LOG_ID='.$this->integration_id); | |
/* -[ UPDATE - SEGUE A MESMA LÓGICA DO INSERT ]- */ | |
$qry = 'SELECT * FROM TB_LOG_INTEGRACAO WHERE LOG_ID = ' . $integration_id; | |
$result = $this->conn->Execute($qry); // Seleciona o registro | |
// chama o método que fará a montagem da query de acordo com o banco. | |
$sql = $this->conn->getUpdateSql($result, $updateData); // $updateData é um array associativo com os dados (igual no insert) | |
$this->conn->Execute($sql); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment