Query mysql_query does not return column [closed]

1

Greetings to everyone in the community. I'm going through a strange problem. When I select the syntax of the query and colon in PHPMyAdmin, the query returns all the fields I want. But when I put it in the code, it does not return any value.

I have a table of users [users] that contains the company to which it is filled by the field [users]. [emp] that is indexed with the table companies [sjy_empresas] that contains a field that links it to an economic group [sjy_groups]. [group] that is indexed to the group table [sjy_group].

I need to get a list of fields from the flag table [sjy_bandeiras]. [flag] that are contained in the companies table [sjy_empresas]. [flag] if these companies belong to the economic group [sjy_empresas]. user belongs to the field companies [users]. [emp].

I have already tested the $ user variable and it is working.

I'm trying to run this code but the query does not return any value. Where is the error?

    $title = BD::conn()->prepare("SELECT 'usuarios'.'usuario_id', 'sjy_grupo'.'id_grupo' FROM 'sjy_grupo' INNER JOIN 'sjy_empresas'  ON 'sjy_grupo'.'id_grupo' = 'sjy_empresas'.'grupo' INNER JOIN 'usuarios' ON 'sjy_empresas'.'id_empresa' = 'usuarios'.'emp' WHERE 'usuario_id' =  ? GROUP BY 'usuarios'.'usuario_id', 'sjy_grupo'.'id_grupo' LIMIT 0, 1");

    $title->execute(array($usuario));
    $dados = $title->fetch();
    $grupo = $dados['id_grupo'];
    $query = "SELECT sjy_grupo.id_grupo, sjy_bandeira.id_bandeira, sjy_bandeira.bandeira
                    FROM sjy_bandeira INNER JOIN 
                    sjy_grupo INNER JOIN sjy_empresas ON sjy_grupo.id_grupo = sjy_empresas.grupo 
                    AND sjy_bandeira.id_bandeira = sjy_empresas.bandeira
                    WHERE id_grupo = $grupo
                    GROUP BY sjy_grupo.id_grupo, sjy_bandeira.id_bandeira, sjy_bandeira.bandeira";

    $result = mysql_query($query);
    while($fetch = mysql_fetch_row($result)){
        echo "<option value='?id=724&band=". $fetch[0] . "'>" . $fetch[2] . "</option>";
    }
    
asked by anonymous 30.08.2017 / 17:43

1 answer

1

The mysql_query and mysql_fetch_array belong to the old PHP API:

This old API whose functions start with mysql_ are discontinued and have been removed in PHP7.

The method that invoked BD::conn()->prepare() is probably mysqli->prepare that is part of New API MySql i

The functions mysql_ DO communicate with the functions mysqli_ (and neither in the OO style: mysqli-> ), that is not how your code works because it is mixing two APIs different.

Do not use the old API

As I said at the beginning, functions that start with mysql_xxxxx are old API functions, so do not use them because they were removed in PHP7 and PHP5 it was already considered obsolete, if at the beginning of your code you are using mysqli then just set everything to mysqli, if you are using the object-oriented style, then stick to it, I recommend you read the documentation and see the examples:

  

Read more at:

     
    
30.08.2017 / 17:52