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.
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?
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/PHPhelp/com...