Enthusiast Programmer
Enthusiast Programmer

Reputation: 171

Fatal error Out of memory fetching data from mysql database

Hello I am facing problem with memory limit.

Please find the code below and let me guide if any thing mistake in my code.

function getRecords($table, $limit = '') {
    global $db;
    if (isNotEmpty($limit)) {
        $intLimit = intval($limit);
        $sql = "SELECT * FROM $table limit $intLimit";
    } else {
        $sql = "SELECT * FROM $table";
    }
    $sth = $db->query($sql);

    return $sth->fetchAll();
}

Thank you.

Upvotes: 1

Views: 668

Answers (2)

Enthusiast Programmer
Enthusiast Programmer

Reputation: 171

With the help of Mayank I have solved this issue. I have just set the limit in this code.

Thanks All

Upvotes: 0

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

If your query is taking so much time then you have to work on it. Always use some optimization techniques in this case:

  • Never use SELECT *, until all column are required
  • Never select all rows until required. Use LIMIT OFFSET instead

Upvotes: 1

Related Questions