Problem with double php query


This is the code I'm trying and the second query does not make me, in the second while I get a message. I try to save people with an array and their roles in a vector, if you can not do double queries, in what way can it be done?

    if ($stmt = $this->conexion->prepare('SELECT * FROM usuarios where Email != ?')) {
        $u = null;
        $usus = [];
        $stmt->bind_param("s", $email);
        $stmt->bind_result($email, $nombre, $pass, $foto);

        while ($stmt->fetch()) {

            $sql = "SELECT roles.Nombre_rol FROM roles, roles_asignados, usuarios WHERE usuarios.Email=roles_asignados.Id_usuario and roles_asignados.Id_rol=roles.Id_rol and usuarios.Email ='" . $email . "'";
            $result = $this->conexion->query($sql);
            $u = new Persona($email, $nombre, $pass, $foto, '');
            $rol = null;

              while ($row = $result->fetch_array()) {

              $rol[] = $row[0];

              $usus[] = $u;

        return $usus;

asked by Esther 24.11.2018 в 14:33

1 answer


I also had a problem similar to yours in a view to many queries, in the end I came to the conclusion that the problem results in the threads that the pc handles, which saturate the view so he puts the errors or warnings. I would think that you should rethink the way you do those queries and simplify the requests to mysql, in this way you will not saturate the threads of the pc. I had to rethink the code and in this way I managed not to saturate the threads of the PC.

answered by 26.11.2018 в 14:34