Query does not return fetch_array

Asked

Viewed 376 times

-1

I’m trying to make a query however, although the query works well in Phpmyadmin in the browser returns the message below:

Fatal error : Call to Undefined method Pdostatement::fetch_array() in D: xampp htdocs final inc projecao.php on line 73

My code is like this:

 $sql = BD::conn()->prepare("SELECT 
    sjy_empresas.nick, 
    pe_orclinhas.dc, 
    pe_orcgrupos.grupo_orcamento, 
    pe_orclinhas.orclinha, 
    pe_orclinhas.id_orclinha, 
    pe_premorc.exercicio, 
    pe_premorc.emp, 
    pe_premorc.anterior, 
    pe_premorc.prj
    FROM sjy_empresas 
    INNER JOIN pe_orcgrupos 
    INNER JOIN pe_orclinhas ON pe_orcgrupos.id_orca = pe_orclinhas.orcgrupo
    INNER JOIN pe_premorc ON pe_orclinhas.id_orclinha = pe_premorc.linhabud
    AND sjy_empresas.id_empresa = pe_premorc.emp
    WHERE pe_premorc.emp = ?
    AND pe_premorc.exercicio = ?
    AND pe_orclinhas.id_orclinha = ?");

    $sql->execute(array($emp, $exercicio, $ans));                               
    $dt = $sql->fetch();

    $nick    = $dt('nick'); // Essa é a linha 75
  • 1

    You’ve already given one var_dump($dt) ???

  • Yes, and the fields are coming normally. Only as string: array(9) { ["nick"]=> string(14) "Example TOY SP" ["dc"]=> string(1) "X" ["group_budget"]=> string(9) "Show Room" ["orclinha"]=> string(5) "Etios" ["id_orclinha"]=> string(3) "460" ["exercicio"]=> string(4) "2018" ["emp"]=> string(1) "4" ["previous"]=> string(4) "0.00" ["prj"]=> string(4) "0.00" }

  • 1

    So it is $dt['nick'] got it?

  • Oops!!! I understood yes. Thank you

2 answers

1


  • Now you are giving this error Fatal error : Function name must be a string in D: xampp htdocs final inc projecao.php on line 75

  • Data type error. See line 75 of projecao.php... or post the code.

  • The code is posted but I will post here too $sql->execute(array($emp, $exercicio, $ans)); $dt = $sql->fetch(); $nick = $dt('nick'); // This is line 75

  • 1

    First confirm that the array is being generated print_r($dt);
die();... what it probably is... and I also believe that it is $nick = $dt['nick']; because it’s printing an array. But go in parts, understand what you’re doing, which will work !

0

$sql->execute(array($emp, $exercicio, $ans));                               
$dt = $sql->fetchAll(PDO::FETCH_ASSOC);
  • Now you are giving this error Fatal error : Function name must be a string in D: xampp htdocs final inc projecao.php on line 75

Browser other questions tagged

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