0

I have created a view called stats that selects the sum of records that adhere to a certain attribute

CREATE VIEW stats
AS
SELECT
    SUM(CASE WHEN attribute = '1' THEN 1 ELSE 0 END) AS attribute1,
    SUM(CASE WHEN attribute = '2' THEN 1 ELSE 0 END) AS attribute2
FROM table
GO

The view is created fine and when I say SELECT * FROM stats in SQL Server Management Studio the results show up fine.

The problem is when I use PHP to grab the data:

$GRAB_STATS_DATA = $DBH->query("SELECT * FROM stats");
while($row = $GRAB_STATS_DATA->fetch()){
    $attribute1 = $row['attribute1'];
    ... // and so on
}

I get an error saying [PHP Fatal error: Maximum execution time of 300 seconds exceeded in C:\ ... on line 17]

Why does the above timeout using PHP (or take longer than 300sec to execute) but display fine in SQL Server Management Studio?

9
  • it could be that you are not communicating well with your DB server? Commented Oct 24, 2014 at 8:03
  • @AresDraguna, please elaborate? All other comms with DB are good. Commented Oct 24, 2014 at 8:06
  • place a die() right before the grabbing. so right before while() to see if you exceed the time before on in while Commented Oct 24, 2014 at 8:07
  • @AresDraguna, ok, I added die() just before the while() and the page refreshes fast, only the information is not displayed. So it seems that the time is exceeded before the while()? Commented Oct 24, 2014 at 8:10
  • 1
    PDO? Use foreach($GRAB_STATS_DATA->fetchAll() as $row){ Commented Oct 24, 2014 at 8:11

1 Answer 1

2

Use:

foreach ($GRAB_STATS_DATA->fetchAll() as $row){
  $attribute1 = $row['attribute1'];
    ... // and so on
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.