0

I have come across an odd issue that I don't know how to resolve. I am using Angular, PHP Slim Restful API, MySQL db.

Two of my db tables have 1k + rows.

When I try to query these tables I get a 500 Internal Server Error from Angular. If I drop the table rows down to below 50 the query works with no errors.

HOWEVER, when I am on my local drive (dev site) I can query the tables with 1k + rows with no problems.

Does anyone have any ideas why this is happening and a solution?

EDIT : here is the code to query the db. The while loop does not run

try{
        $a = array();
        $w = "";
        $row_data = array();
        foreach ($where as $key => $value) {
            $w .= " and " .$key. " like :".$key;
            $a[":".$key] = $value;
        }
        $stmt = $this->db->prepare("select ".$columns." from ".$table." where 1=1 ". $w);
        $stmt->execute($a);
        //$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $row_count = $stmt->rowCount();
        syslog(LOG_WARNING, "DATA COUNT= ".print_r($row_count,true));
        if(count($row_count)<=0){
            syslog(LOG_WARNING, "DATA NO ROWS");
            $response["status"] = "warning";
            $response["message"] = "No data found.";
        }else{
            $response["status"] = "success";
            $response["message"] = "Data selected from database";
            syslog(LOG_WARNING, "DATA HAVE ROWS");
            ===================
            while ($rows = $stmt->fetch(PDO::FETCH_ASSOC)) {
                $row_data[] = $rows;
            }
            ===================
            syslog(LOG_WARNING, "DATA JASON= ".print_r($row_data,true));
            $response["data"] = $row_data;

        }

        syslog(LOG_WARNING, "DATA END");

    }catch(PDOException $e){
        $response["status"] = "error";
        $response["message"] = 'Select Failed: ' .$e->getMessage();
        $response["data"] = null;
    }
    return $response;
Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49
Jason
  • 1,091
  • 4
  • 19
  • 40
  • 4
    Error 500 is a server error; check your logs. – Funk Forty Niner Mar 29 '16 at 16:08
  • checked them. everything checks out. If I reduce the rows in the db to under 50 everything works. over 50 I get the 500 error msg. My guess is It has something to do with the number of objects it is receiving – Jason Mar 29 '16 at 16:09
  • I'm guessing you have a json api running on PHP Slim - if so then try to access whatever url you're using to fetch the table rows directly in the browser. Ie `thesite.com/rows.json?count=100` and see if you get a 500 internal server error (I guess you will). Then you have ruled out Angular and need to figure out what's wrong, it should be in the Slim application or web server error logs. – JimL Mar 29 '16 at 16:11
  • 1
    my guess is that your php script is timing out. Use `set_time_limit(0)` http://php.net/manual/en/function.set-time-limit.php – cmorrissey Mar 29 '16 at 16:14
  • Like Fred mentioned a 500 error is a server side error and not an Angular error. The best thing to do is to use something like Postman to hit your service and see what is actually happening. – Gremash Mar 29 '16 at 20:01

0 Answers0