0

Looking on my error log I get the following error a lot:

[01-Mar-2011 04:31:27] exception 'Exception' with message 'Query failed' in /home1/mexautos/public_html/kiubbo/data/model.php:89
Stack trace:
#0 /home1/mexautos/public_html/kiubbo/data/article.php(275): Model::execSQl2('update articles...')
#1 /home1/mexautos/public_html/kiubbo/data/article.php(111): Article->save()
#2 /home1/mexautos/public_html/kiubbo/pages/frontpage.php(21): Article->calculateRanking()
#3 /home1/mexautos/public_html/kiubbo/pages/frontpage.php(27): FrontPage->updateRanking()
#4 /home1/mexautos/public_html/kiubbo/index.php(15): FrontPage->showTopArticles('')
#5 {main}

If I go to the model.php file I see this:

static function execSQl2($query)
    {
    /*
            Execute a SQL query on the database
            passing the tablename and the sql query.
            Returns the LAST_INSERT_ID
    */


        $db = null;
        $lastid = null;
        //echo "query is $query";

        try
        {
            $db = Model::getConnection();
            $results = $db->query($query);
            if(!$results) {
                throw new Exception('Query failed', EX_QUERY_FAILED );
            }
            $lastid = $db->insert_id;
        }
        catch(Exception $e)
        {
            /*  errors are handled higher in the
                    object hierarchy
            */

            throw $e;
        }

Does Anybody see an error, or i should look somewhere else?

Thank you and Regards, Carlos

Edit:

This is the query: $lastid = parent::execSql2($query);

And this is the context:

function save() {

    /*
            Here we do either a create or
            update operation depending
            on the value of the id field.
            Zero means create, non-zero
            update
    */

        if(!get_magic_quotes_gpc())
        {
            $this->title = addslashes($this->title);
            $this->description = addslashes($this->description);
        }

        try
        {
            $db = parent::getConnection();
            if($this->id == 0 )
            {
                $query = 'insert into articles (modified, username, url, title, description, points )';
                $query .= " values ('$this->getModified()', '$this->username', '$this->url', '$this->title', '$this->description', $this->points)";

            }
            else if($this->id != 0)
            {
                $query = "update articles set modified = NOW()".", username = '$this->username', url = '$this->url', title = '".$this->title."', description = '".$this->description."', points = $this->points, ranking = $this->ranking where id = $this->id";
            }

            $lastid = parent::execSql2($query);

            if($this->id == 0 )
                $this->id = $lastid;

        }
        catch(Exception $e){
            error_log($e);
        }
    }

Regards, Carlos

3
  • 1
    Which query is getting failed? What is the query? post the query too Commented Mar 1, 2011 at 12:00
  • 1
    Throw the exception message with mysql error message. Do not change it to your custom message otherwise it will be very difficult to identify issue for you Commented Mar 1, 2011 at 12:03
  • How can I find our the query with the error? That is what I am trying to find. So to fix the custom message should I just delete 'Query failed' on: throw new Exception('Query failed', EX_QUERY_FAILED ) ? Thank you Commented Mar 1, 2011 at 20:12

2 Answers 2

2

As heximal said, it's probably an error in your SQL query. Copy and paste the full SQL being queried into PhpMyAdmin or a similar tool and see what errors (if any) come up. Often, the problem is simply a mistyped table or a missing value. Of course you can also post the query here if you want SO help with it! :D

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, How can I find: the full SQL being queried ? Should I start in the files on the error message? article.php , frontpage.php , index.php ? Regards,Carlos
Check /home1/mexautos/public_html/kiubbo/data/article.php line 275. The query should begin with 'update articles'. Paste this query on SO so we can check it.
1

The error is propably in sql-query. Append to log query text and analyze it.

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.