Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Errors not showing with an Exception
Post Flair (click to view more posts with a particular flair)
Post Body

Had this function:

public function insert($table, $parameters)
{
    // format the MySQL query
    $sql = sprintf(
        'INSERT INTO mytodo.%s (%s) VALUES(%s)',
        $table,
        implode(', ', array_keys($parameters)),
        ':'.implode(', :', array_keys($parameters))
    );
    // die(var_dump($sql));

    try {
        // build up the SQL query
        $statement = $this->pdo->prepare($sql);
        $statement->execute($parameters);
        //require 'controllers/index.php';
    } catch (Exception $e) {
        var_dump($e);
        $e->getMessage();
        //require 'controllers/404.php';
    }

    //        die(var_dump($sql));
}

and it just wasn't working no matter what I did (checked whether my $sql was correct or not, whether I was doing the PDO thing correctly. And I would never see any error message with the exception I caught (it was going to the catch block). It wasn't until I did the var_dump($e) that I saw that there really was an Exception in that $e, but getMessage() wasn't showing it.

I got this:

" args: (array)
[1 element] 0: (array)
[1 element] name: (string) "yoyo" 1: (array)
[6 elements] file: (string) ".../add-name.php" line: (integer) 11 function: (string) "insert" class: (string) "QueryBuilder" type: (string) "->" args: (array)
[2 elements] 0: (string) "users" 1: (array)
[1 element] name: (string) "yoyo" 2: (array)
[4 elements] file: (string) ".../index.php" line: (integer) 9 args: (array)
[1 element] 0: (string) "/.../add-name.php" function: (string) "require" previous:Exception:private: (null) NULL errorInfo: (array)
[3 elements] 0: (string) "HY000" 1: (integer) 1364 2: (string) "Field 'id' doesn't have a default value"

So now I actually see the real error with the "Field 'id' doesn't have a default value", so I can search whatever that is, but how come $e-getMessage() didn't work?

Author
Account Strength
90%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,159
Link Karma
629
Comment Karma
530
Profile updated: 2 days ago
Posts updated: 5 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago