Problem with Mysql and php connection

Asked

Viewed 204 times

0

I’m trying to connect to the database to remove data that is returned with the get_data function: Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\hortsustentasp.eco.br\_conexoes_graficos\envia.php on line 35 ,that is, this falling in the if($resultados === FALSE).

I have no idea why this occurs and even more only in the second interaction. There is some error in the code?

The values given the variables have been thought for all the calls the function will return data.

    $subCultura_id=5;
    $cidade=array(2,1);
    $ano=2000;
    $ano2=2015;
    $fonte=2;
    $tipo=6;

    include("../conecta.php");

    $culturas=array();
    echo "tamanho:".count($cidade);
    for($i=0;$i<count($cidade);$i++){

     echo "<br>i: ".$i."<br>";

     $query="CALL get_dados_producao_graficos({$tipo},{$cidade[$i]},{$ano}                                                  {$ano2},{$subCultura_id},{$fonte});";

     echo $query."<br><br>";

     $resultados = mysqli_query($conexao,$query);

     if($resultados === FALSE) { 
       die(mysqli_error());
     }

     while($resultado = mysqli_fetch_assoc($resultados)){

       if($resultado['valor'] > 0){
         array_push($culturas,$resultado);
       }
     }

    }

Outturn:

    tamanho:2
    i: 0
    CALL get_dados_producao_graficos(6,2,2000,2015,5,2);


    i: 1
    CALL get_dados_producao_graficos(6,1,2000,2015,5,2);


    Warning: mysqli_error() expects exactly 1 parameter, 0 given in         C:\xampp\htdocs\hortsustentasp.eco.br\_conexoes_graficos\envia.php on line 35
  • 1

    Your query failed, and the function mysqli_error() has a mandatory parameter which is the connection, leave so mysqli_error($conexao)

  • I changed the order of the arguments but did not fix, the first interaction also gave the same error with this and this error: Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\hortsustentasp.eco.br\_conexoes_graficos\envia.php on line 31

  • Don’t touch the mysqli_query() only in the mysqli_error() it will return the error message from the database.

  • I changed myqli_error() and returned: Commands out of Sync; you can’t run this command now. I found in the Mysql manual that the function mysql_free_result($resultados); but it didn’t work.

  • Ai blz, now you have the real problem. The message seems that you ran two or more queries and did not signal the end of them, SP are kind of boring ... you can not send two queries together, have to make a close/ store the result and then yes do the next.

  • Is there any other way to do without closing and opening to each interaction?

  • Have yes to mounting a response here and testing of course xD

  • Thank you very much!

  • Sorry for the mistake, I had misinterpreted the manual, the arguments are correct :/

  • No problem, thanks for the initiative.

  • This solves the problem: http://answall.com/a/16309/91

  • Thank you, you would know to tell me what causes this mistake?

  • It worked perfectly, thanks again.

Show 8 more comments
No answers

Browser other questions tagged

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