здесь мой простой класс
<?php error_reporting(E_ALL); ini_set('display_errors', 1); class Test{ private $dsn = 'mysql:host=localhost;dbname=scem;'; private $db; function __construct() { $this->db = new PDO($this->dsn, "user", "pw"); try { $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch (PDOException $e) { die("Unable to connect to DB with user / pass " . $e); } } public function doTest(){ try { $pdoSql = "INSERT INTO pscoperation_history VALUES (?,?,?,?,?,?,?,?,?,?,?)";// ON DUPLICATE KEY UPDATE pscclass = ?"; $stmt = $this->db->prepare($pdoSql); $result = $stmt->execute(array("2015-04-17 03:01:09", 519, 0, 0, "9999", "15", null, null, null, null, null, "15")); } catch (PDOException $ex) { ob_end_flush(); echo($ex->getMessage()); flush(); ob_start(); die("error trying to insert"); } } } $test = new Test(); $test->doTest();
Структура моей таблицы
-- -- Table structure for table `pscoperation_history` -- CREATE TABLE IF NOT EXISTS `pscoperation_history` ( `version_stamp` datetime NOT NULL, `pscoperation_id` int(11) unsigned NOT NULL, `is_realversion` tinyint(4) NOT NULL DEFAULT '0', `is_deleted` tinyint(4) NOT NULL DEFAULT '0', `version_author` int(11) NOT NULL, `pscclass` int(11) unsigned DEFAULT NULL, `visibility` enum('+','#','-','~') DEFAULT NULL, `pscopname` varchar(50) DEFAULT NULL, `returndatatype` varchar(50) DEFAULT NULL, `pscopmodifier` int(11) unsigned DEFAULT NULL, `pscopnote` text, PRIMARY KEY (`version_stamp`,`pscoperation_id`), KEY `pscclass` (`pscclass`), KEY `pscoperation_id` (`pscoperation_id`), KEY `version_stamp` (`version_stamp`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='InnoDB free: 11264 kB; (`project`) REFER `scem/projects`(`pr'; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
вопрос: почему это не вызывает дублируемую ключевую ошибку? он выполняется без каких-либо проблем.