Getting data from MYSQL into JSON using PHP

后端 未结 5 535
挽巷
挽巷 2021-02-02 03:54

I have the following quite simple test PHP code that extracts the data and puts it into JSON formatted text.

I get the following error..

Fatal err

5条回答
  •  野性不改
    2021-02-02 04:03

    As a first work-around set it to something like 256M or even 512M.

    It is probable the dataset that MySQL is returning to you is quite big. So even if your PHP is very memory-efficient, you still will get the OoM error. So as a more viable long-term solution use the LIMIT statement (SELECT * FROM $table WHERE 1=1 LIMIT 0,30 (start from index 0, get 30 items).

    EDIT: Oh wow, I didn't even see the problem from the first solution... Well, still might be a good idea to LIMIT your query :-)

提交回复
热议问题