2

Problem:

The following database operation fails the statement execute method fails silently, I can see 'lol' printed but not 'derp' so I know the prep is all good, it just fails at execute().

No idea what could be causing this error, I know the DB is functioning as I can pull values from it using SQL statements with prepare() and execute(). Any help would be greatly appreciated...

        $category = 'Derpenstien';
        $order = 1;
        $parentID = 1;

        $query = "insert into category (name, ordering, parent_id) values (:name, :ordering, :parent)";
        $newEntry = $db->getdb()->prepare($query);
        $newEntry->bindParam(':name', $category, \PDO::PARAM_STR);
        $newEntry->bindParam(':ordering', $order, \PDO::PARAM_INT);
        $newEntry->bindParam(':parent', $parentID, \PDO::PARAM_INT);

        var_dump('lol');

        $newEntry->execute();

        var_dump('derp');
KGR
  • 21
  • 6
  • 2
    Put `error_reporting(E_ALL); ini_set("display_errors", 1);` at the start of your script. Odds are, if you're working with some framework, that it's suppressing the errors via some config file since it thinks it's on live. – Andrei Jun 03 '15 at 11:44
  • @Andrew: erm, that probably won't help. By default, PDO does not raise exceptions/trigger errors. You need to override it for each instance - and even then it doesn't cover every scenario. You should check the return value of pdo::execute(), *and* poll pdo::errorCode() as well as adding an exception handler – symcbean Jun 03 '15 at 13:02
  • 1
    Ah, you're absolutely right. Forgot about that. [Look here for how to set error mode for PDO](http://php.net/manual/en/pdo.error-handling.php). – Andrei Jun 03 '15 at 13:10
  • Turns out permissions on the folder weren't set... works now with a quick chmod 777 : ) – KGR Jun 03 '15 at 15:19

0 Answers0