0

Just getting started with PDO

I tried debugging my queries, but I receive no logfile

try{

$stmt = $db->prepare(
"INSERT INTO psc_history 
(version_stamp, psc_id,version_author , pscname) VALUES 

(:version_stamp, :tableprimkeyvalue, :version_author, :fieldvalue)

ON DUPLICATE KEY UPDATE pscname = :fieldvalue2, version_author = :version_author2;");

            $stmt->execute(array(':version_stamp' =>  "2015-09-23 01:14:59"
                           , ':tableprimkeyvalue' => 5478
                              , ':version_author' => 9999
                                  , ':fieldvalue' => "hello1"
                                 , ':fieldvalue2' => "hello2"
                             , ":version_author2" => 9999));

        } catch (PDOException $ex) {
        echo($ex->getMessage());
    }

Nothing gets written to the table

version_stamp and psc_id are primary keys

I get no error neither.

What am I missing?

EDIT

when changing the psc_id to a new value that does not exist: the record gets inserted

when changing the datetime to a value that does not exist: the record does not get inserted

maybe a problem with my DB setup?

enter image description here

Community
  • 1
  • 1
Toskan
  • 13,911
  • 14
  • 95
  • 185
  • Add `$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);` right after the connection is opened. Including error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Sep 23 '14 at 00:20
  • If at least "one" value tries to be inserted in a UNIQUE column, your entire query will fail. Try `ON DUPLICATE KEY UPDATE` http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html - plus, have you included error reporting as stated above? That should have thrown an error. – Funk Forty Niner Sep 23 '14 at 00:31
  • there was no error, i found the solution though (remove unique index contraint) – Toskan Sep 23 '14 at 07:08
  • 1
    SQL was failing silently because of it then. I had a feeling that removing the constraint would have solved it. – Funk Forty Niner Sep 23 '14 at 07:10

1 Answers1

0

you had to remove the unique constraint from the column in phpmyadmin structure indexes edit change unique to index

enter image description here

Toskan
  • 13,911
  • 14
  • 95
  • 185