Perform an external-based query in the Zend Framework

Asked

Viewed 18 times

0

Model

  public function excluirFiliadosNaoEnviados($base)
{



      $sql = "SELECT FROM " . $base . ".debito_automatico";
      $acao = $this->conexao->prepare($sql);  
      if($acao->execute()){
        return true;
      }else{
        return false;
      } 


}

Control

public function prepararfiliadosAction()
{

    $base = DATABASE_GERAL;


    if($this->repositorio->excluirFiliadosNaoEnviados($base)) {
        echo $this->repositorio->prepararFiliados($this->getMesCompetencia()) ? 'true' : 'false';
    }

    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(TRUE);
}

Query not working always returning false.

1 answer

1


Create a model

<?php
class Application_Model_Inusuarios extends Zend_Db_Table_Abstract
{
    protected $_name    = 'in_usuarios';
    protected $_primary = array('id');
    protected $_dependentTables = array(
        "Application_Model_Inordem",
    );

    protected $_referenceMap = array(

        'Inloja' => array(
            'refTableClass'     => 'Application_Model_Inloja',
            'refColumns'        => 'id',
            'columns'           => 'loja_id'
        )
    );
}

In your Voce action you can use the model to mount your query

public minhaAction(){

$modelUser = new Application_Model_Inusuarios();

$usuarioAtual = $modelUser->find($id)->current();


$sqlUsuariosAtivos   = $modelUser->select()->where("usuario_status = 'ativo'")->forceIndex("usuario_status");
$resultado = $modelUser->fetchAll($sqlUsuariosAtivos);
foreach ($resultado as $user){
    print_r($user);
}

}

Browser other questions tagged

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