Warm regards. You see, I have a table "movements" with approximately 300 thousand records, which I wish to obtain through PHP, but at the time of making my query, I do not get results, unless I put a LIMIT.
This is my code:
$query = "SELECT * FROM movimientos";
$sql = $this->conex->prepare($query);
$sql->execute();
$movimientos = $sql->fetchAll(PDO::FETCH_ASSOC);
if($sql->rowCount()>0) var_dump($movimientos);
else echo "No hay movimientos";
The detail is that, as I said, it does not give me results, it does not even enter the "else", only my script remains blank.
BUT, if I modify my query to:
$query = "SELECT * FROM movimientos LIMIT 50000";
Then if I get my results.
Why could this be happening? I researched a bit, and I found something related to the variables post_max_size and memory_limit, of the php.ini. I have already increased these values but I still do not get results.
I hope you can help me, thank you in advance. Greetings!
------------------- Edited (Solution) -----------------
Sorry, I had not had time to share my solution. I warn that I do not know if it is the most advisable, you will think ... But it was what worked for me.
Firstly, I had to increase the memory_limit variable in my php.ini to 3MB (I know, too! ... not recommended, but believe me without this, my script does not work). The variable set_time_limit (configured at 1 min) did not represent a problem, since the script did not die by time, but by memory / buffer size (or so I understood it); so I did not have to increase it.
Afterwards, I had to make an adaptation in my query, to get the results, thanks to the help provided in the developer's website, I was suggested to make these changes.
I had my script in the manner mentioned above, and it was like this:
function prueba(){
$query = "SELECT * FROM tarjetas";
$sql = $this->conex->query($query); //Se ejecuta directo la consulta, ya que no hay parámetros
$sql->setFetchMode(PDO::FETCH_ASSOC);
$movs = array(); //array auxiliar para guardar los movimientos
while ($row = $sql->fetch()) { //recomerremos una a una las filas obtenidas
array_push($movs, $row); //guardamos el elemento en el array auxiliar
unset($row); //eliminamos la fila para evitar sobrecargar la memoria
}
return $movs;
}
This is how my script was, as I repeat, it was what worked for me. I hope someone can serve you, and can comment about it. Greetings and thanks to everyone!