Store a query attribute in a variable

Asked

Viewed 33 times

1

I have the following consultation:

<?php
     define("DATABASE_MS_DB_98", "Cont98");
     $conninfo98 = array("Database" => DATABASE_MS_DB_98, "UID" => USER_MS_DB, "PWD" => PASS_MS_DB, "CharacterSet"  => 'UTF-8');
     $conexao98 = sqlsrv_connect(SERVER_MS_DB, $conninfo98);

     $query =  " SELECT ano_empenho "
             . " ,num_empenho "
             . " ,finempe.orgao_unid "
             . " ,orcorgao.descricao orgao " 
             . " ,orcunid.descricao unidade "
             . " ,finempe.codigo_orgao "
             . " ,finempe.codigo_unidade "
             . " ,programatica "
             . " ,funcao "
             . " ,programa "
             . " ,sub_programa "
             . " ,tipo_pa"
             . " ,projeto_ativ "
             . " ,conta_desp "
             . " ,categoria "
             . " ,elemento "
             . " ,sub_elemento "
             . " ,desdobramento "
             . " ,sub_item "
             . " ,nome_fornecedor "
             . " ,cod_forn "
             . " ,valor_empenhado "
             . " FROM finempe "
             . " INNER JOIN orcorgao on "
             . " (finempe.codigo_orgao  = orcorgao.codigo_orgao ) "
             . " INNER JOIN orcunid on "
             . " ((finempe.codigo_orgao = orcunid.codigo_orgao) and (finempe.codigo_unidade = orcunid.codigo_unidade)) "
             . " WHERE finempe.data_empenho between convert(datetime,'1998-01-01') and convert(datetime,'1998-12-31') and finempe.codigo_orgao = 01 and finempe.codigo_unidade = 01 " // usuario seleciona o periodo, o orgao e a unidade
             . " ORDER BY orgao_unid,num_empenho,ano_empenho, finempe.programatica, finempe.data_empenho;" ;

     $params = array();
     $options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

     $resultado = sqlsrv_query($conexao98, $query, $params, $options) or die(print_r(sqlsrv_errors()));

     $total = 0;
                            ?>

I would like to store "orcunid.descricao_drive" in a variable, how could I do this in php?

1 answer

2


After a brief search I found the following solution:

$linha = sqlsrv_fetch_array($resultado);
$unidade = $linha["descr"];

Browser other questions tagged

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