PHP code to query MYSQL leaking memory

0

All good people? Guys I'm having a problem that I had not encountered before. I wrote the code below and at the time of opening the page by localhost in the browser it returns the following error:

  

Fatal error: Allowed memory size of 134217728 bytes in C: \ xampp \ htdocs \ site_almoxarifado_testes \ control_material.php on line 1

                               Stock Control     

<body id="corpo">
    <header id="cabecalho">

    </header>
    <section id="titulo_principal">
        <form method="post" action="funcoes.php">
            <input type="text" name="pesquisar" size="126" placeholder=" exp: cabo 4mm ...">
            <input type="submit" value="Buscar">
        </form>
        <nav id="menuTabela">
            <ul type="disc">
                <li><a class="tabela" href="controle_material.php">Id's das Cidades</a></li>
                <li><a class="tabela" href="controle_notas.php">Nome das Cidades</a></li>
                <li><a class="tabela" href="saida_material.php">Estados</a></li>
            </ul>
        </nav>
        <div id="principal">
            <table id="tabela2">
                <?php if (isset($pesquisar)) {
                    while ($rows_cursos = $resultado_busca->fetch_assoc($resultado_busca)) {
                        echo utf8_encode($rows_cursos['nome_cidade']);
                    }
                } else { while ($colunas = $selecao_geral->fetch_assoc()) {?>
                        <tr>
                            <td id="td"><?php echo utf8_encode($colunas['idcidade']); ?></td>
                            <td id="td1"><?php echo utf8_encode($colunas['nome_cidade']); ?></td>
                            <td id="td2"><?php echo utf8_encode($colunas['uf']); ?></td>
                        </tr>
                    <?php }
                 } ?>
            </table>
        </div>
    </section>
    <aside>

    </aside>
    <footer id="rodape">

    </footer>
    <?php $conecta->close(); ?>
</body>

This is the code for funcoes.php

include 'controle_material.php';

define("SERVIDOR", "localhost");
define("USUARIO", "root");
define("SENHA", "");
define("BANCODEDADOS", "controle_almoxarifado");

$conecta = new mysqli(SERVIDOR, USUARIO, SENHA, BANCODEDADOS);

if ($conecta->connect_error) {
    trigger_error("ERRO NA CONEXÃO: " . $conecta->connect_error, E_USER_ERROR);
}

$pesquisar = $_POST['pesquisar'];

//$pesquisa_tabela = mysqli_query($conecta, 'select * from cidade where nomes like %pedro%');
$selecao_geral = mysqli_query($conecta, "select * from cidade");

$resultado_busca = mysqli_query($conecta, "select * from cidade where nome_cidade like %$pesquisar%");

? >

    
asked by anonymous 28.09.2018 / 02:14

1 answer

1

Well, I do not know how much memory it takes to allocate your query, but to fix this problem you can either increase the memory limit to be used by php.ini or simply use ini_set to set the your runtime memory limit

<?php
    ini_set("memory_limit","256M");
?>

where '256M' represents the amount of memory, in MegaBytes, to be used.

The ini_set sets a new value for the indicated configuration option. The configuration option will retain the new value while the script is running and will be restored at the end of the script execution. See more here

    
28.09.2018 / 03:22