I can not see the error (PHP and HTML)

0

I wanted to show the names of the employees and the teams they are part of so that if the user enters a name, it will filter all the teams that that person is part of. It's coming in white.

   try{

                        $pdo = Conexao::getInstance();

                      $consulta = $pdo->prepare("SELECT id_equipe,nome_equipe,GROUP_CONCAT(nome_eletricista) as equipes FROM quadro WHERE id_agencia=:id AND status=1 GROUP BY nome_equipe ORDER BY nome_equipe ASC");

                        $consulta->bindParam(':id',$id_agencia, PDO::PARAM_INT);

                         if($consulta->execute()){

                          if($consulta->rowCount() > 0){

                          while($dados = $consulta->fetch(PDO::FETCH_OBJ)){

                                      $id_equipe= $dados['id_equipe'];
                                      $nome= $dados['nome_equipe'];
                                      $equipe= $dados->nome_equipe;
                                      $equipes=$dados->equipes;


                                      echo'<option value="'.$id_equipe.'">'.$nome.' - '.$equipes.'</option>';

                                          }
                                    }       
                                  }
                    }catch(PDOexception $e){

                        echo "ERROR: " . $e->getMessage();
                      }

                ?>
                              </select>
                              <br>
    
asked by anonymous 02.03.2018 / 13:47

2 answers

0
The MySQL server can operate in different SQL modes and can apply these modes differently for different clients depending on the value of the% / p>

The sql_mode error is generated when you use a non-aggregate value in a query that has only_full_group_by .

There are two ways to fix:

  • Using GROUP BY
$consulta = $pdo->prepare("SELECT ANY_VALUE(id_equipe), nome_equipe, ANY_VALUE(GROUP_CONCAT(nome_eletricista)) AS equipes FROM quadro WHERE id_agencia=:id AND status=1 GROUP BY nome_equipe ORDER BY nome_equipe ASC");
  • Disabling ANY_VALUE when instantiating the PDO object.
$pdo = new PDO("mysql:dbname=testdb;host=127.0.0.1", "root", "123456", [
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""));'
]);
    
02.03.2018 / 14:58
0

Disabling sql_mode.

Do this:

mysql > SET GLOBAL sql_mode = (SELECT REPLACE (@@ sql_mode, 'ONLY_FULL_GROUP_BY', ''));

    
02.03.2018 / 14:35