本文整理汇总了PHP中xPDO::errorCode方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::errorCode方法的具体用法?PHP xPDO::errorCode怎么用?PHP xPDO::errorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDO
的用法示例。
在下文中一共展示了xPDO::errorCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
//.........这里部分代码省略.........
$where = '';
foreach ($pkn as $k => $v) {
$vt = PDO::PARAM_INT;
if (in_array($this->_fieldMeta[$k]['phptype'], array('string', 'float'))) {
$vt = PDO::PARAM_STR;
}
if ($iteration) {
$where .= " AND ";
}
$where .= $this->xpdo->escape($k) . " = :{$k}";
$bindings[":{$k}"]['value'] = $this->_fields[$k];
$bindings[":{$k}"]['type'] = $vt;
$iteration++;
}
} else {
$pkn = $this->getPK();
$pkt = PDO::PARAM_INT;
if (in_array($this->_fieldMeta[$pkn]['phptype'], array('string', 'float'))) {
$pkt = PDO::PARAM_STR;
}
$bindings[":{$pkn}"]['value'] = $pk;
$bindings[":{$pkn}"]['type'] = $pkt;
$where = $this->xpdo->escape($pkn) . ' = :' . $pkn;
}
if (!empty($updateSql)) {
$sql = "UPDATE {$this->_table} SET " . implode(',', $updateSql) . " WHERE {$where}";
}
}
}
if (!empty($sql) && ($criteria = new xPDOCriteria($this->xpdo, $sql))) {
if ($criteria->prepare()) {
if (!empty($bindings)) {
$criteria->bind($bindings, true, false);
}
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Executing SQL:\n{$sql}\nwith bindings:\n" . print_r($bindings, true));
}
$tstart = microtime(true);
if (!($result = $criteria->stmt->execute())) {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
$errorInfo = $criteria->stmt->errorInfo();
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $criteria->stmt->errorCode() . " executing statement:\n" . $criteria->toSQL() . "\n" . print_r($errorInfo, true));
if (($errorInfo[1] == '1146' || $errorInfo[1] == '1') && $this->getOption(xPDO::OPT_AUTO_CREATE_TABLES)) {
if ($this->xpdo->getManager() && $this->xpdo->manager->createObjectContainer($this->_class) === true) {
$tstart = microtime(true);
if (!($result = $criteria->stmt->execute())) {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $criteria->stmt->errorCode() . " executing statement:\n{$sql}\n");
} else {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error " . $this->xpdo->errorCode() . " attempting to create object container for class {$this->_class}:\n" . print_r($this->xpdo->errorInfo(), true));
}
}
} else {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
}
} else {
$result = false;
}
if ($result) {
if ($pkn && !$pk) {
if ($pkGenerated) {
$this->_fields[$this->getPK()] = $this->xpdo->lastInsertId();
}
$pk = $this->getPrimaryKey();
}
if ($pk || !$this->getPK()) {
$this->_dirty = array();
$this->_validated = array();
$this->_new = false;
}
$callback = $this->getOption(xPDO::OPT_CALLBACK_ON_SAVE);
if ($callback && is_callable($callback)) {
call_user_func($callback, array('className' => $this->_class, 'criteria' => $criteria, 'object' => $this));
}
if ($this->xpdo->_cacheEnabled && $pk && ($cacheFlag || $cacheFlag === null && $this->_cacheFlag)) {
$cacheKey = $this->xpdo->newQuery($this->_class, $pk, $cacheFlag);
if (is_bool($cacheFlag)) {
$expires = 0;
} else {
$expires = intval($cacheFlag);
}
$this->xpdo->toCache($cacheKey, $this, $expires, array('modified' => true));
}
}
}
}
$this->_saveRelatedObjects();
if ($result) {
$this->_dirty = array();
$this->_validated = array();
}
return $result;
}