Fatal error: Maximum execution time of 30 seconds exceeded

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lucas20042004
Forum Newbie
Posts: 7
Joined: Mon May 15, 2006 7:39 am

Fatal error: Maximum execution time of 30 seconds exceeded

Post by lucas20042004 »

Hi, my site was working ok yesterday but today it is coming up with this error:

Fatal error: Maximum execution time of 30 seconds exceeded in /xxxxxx/library/classes/class_db.php on line 31

The class_db.php file is below. I hope somebody can help. Thanks

Code: Select all

<?php
class db {
    var $totalquerys=0;
 
    
    function connect($sqlhost, $sqluser, $sqlpass){
        $db=mysql_connect($sqlhost, $sqluser, $sqlpass) or die("Cant connect to Database!");
        return $db;
    }
 
    function select_db($sqldb){
        mysql_select_db($sqldb) or die("Cant select Database");
        $this->totalquerys++;
    }
    
 
    function query($sqlquery){
 
        $result=mysql_query($sqlquery);
        if(empty($result)){
            $sqlerror = mysql_error();
            $line = __LINE__;
            echo "<b>MySQL Returned Error:</b><br/><textarea rows=10 cols=40>$sqlerror</textarea><br />on Line: $line<br /><br /><b>Query:</b><br /><textarea rows=10 cols=40>$sqlquery</textarea>";
            exit();
        }
        $this->totalquerys++;
        return $result;
    }
 
    function qfetch($sqlquery){
        $result=mysql_query($sqlquery);
        if(empty($result)){
            $sqlerror = mysql_error();
            $line = __LINE__;
            echo "<b>MySQL Returned Error:</b><br/><textarea rows=10 cols=40>$sqlerror</textarea><br />on Line: $line<br /><br /><b>Query:</b><br /><textarea rows=10 cols=40>$sqlquery</textarea>";
            exit();
        }
        $row=mysql_fetch_assoc($result);
        return $row;
    }
    
    function fetch($result){
        $row=mysql_fetch_assoc($result);
        return $row;
    }
 
    function num_rows($result){
    $rows=mysql_num_rows($result);
    return $rows;
    }
    
    function qnum_rows($fieldlist, $table, $field="", $value="", $operator="="){
    if(!empty($field)&&!empty($value)) echo "SELECT " . $fieldlist . " FROM sf_" . $table . " WHERE " . $field . " " . $operator . " '" . $value ."'";
    if(!empty($field)&&!empty($value)) $result = $this->query("SELECT " . $fieldlist . " FROM sf_" . $table . " WHERE " . $field . " " . $operator . " '" . $value ."'");
    else $result = $this->query("SELECT $fieldlist FROM sf_$table");
    $rows = $this->num_rows($result);
    return $rows;
    }
    
    function close($conn){
    mysql_close($conn);
    }
}
    $db=new db;
?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Fatal error: Maximum execution time of 30 seconds exceeded

Post by onion2k »

The SQL query that it's trying to do is taking too long. You'll need to either work out which query is taking ages and optimise it, or increase the maximum execution time in php.ini.
timsewell
Forum Newbie
Posts: 21
Joined: Tue Feb 26, 2008 5:43 am
Location: Hove, England

Re: Fatal error: Maximum execution time of 30 seconds exceeded

Post by timsewell »

Without minutely examining the code, when I get that sort of error I immediately look at my loops.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Fatal error: Maximum execution time of 30 seconds exceeded

Post by pickle »

onion2k wrote:The SQL query that it's trying to do is taking too long. You'll need to either work out which query is taking ages and optimise it, or increase the maximum execution time in php.ini.
In my experience, the time PHP waits for an SQL query is not counted in the maximum execution time.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply