本文整理汇总了PHP中F3::sqlBind方法的典型用法代码示例。如果您正苦于以下问题:PHP F3::sqlBind方法的具体用法?PHP F3::sqlBind怎么用?PHP F3::sqlBind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类F3
的用法示例。
在下文中一共展示了F3::sqlBind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
Insert/update DB record
@public
**/
public function save()
{
if ($this->empty) {
// Axon is empty
trigger_error(self::TEXT_AxonEmpty);
return;
}
if (method_exists($this, 'beforeSave')) {
// Execute beforeSave event
$this->beforeSave();
}
$_new = TRUE;
if ($this->keys) {
// If ALL primary keys are NULL, this is a new record
foreach ($this->keys as $_value) {
if (!is_null($_value)) {
$_new = FALSE;
break;
}
}
}
if ($_new) {
// Insert new record
$_fields = '';
$_values = '';
foreach ($this->fields as $_field => $_value) {
$_fields .= ($_fields ? ',' : '') . $_field;
$_values .= ($_values ? ',' : '') . ':' . $_field;
$_bind[':' . $_field] = array($_value, SQLdb::type($_value));
}
F3::sqlBind('INSERT INTO ' . $this->table . ' (' . $_fields . ') ' . 'VALUES (' . $_values . ');', $_bind, $this->db);
} else {
// Update record
$_set = '';
foreach ($this->fields as $_field => $_value) {
$_set .= ($_set ? ',' : '') . ($_field . '=:' . $_field);
$_bind[':' . $_field] = array($_value, SQLdb::type($_value));
}
// Use prior primary key values (if changed) to find record
$_cond = '';
foreach ($this->keys as $_key => $_value) {
$_cond .= ($_cond ? ' AND ' : '') . ($_key . '=:c_' . $_key);
$_bind[':c_' . $_key] = array($_value, SQLdb::type($_value));
}
F3::sqlBind('UPDATE ' . $this->table . ' SET ' . $_set . (is_null($_cond) ? '' : ' WHERE ' . $_cond) . ';', $_bind, $this->db);
}
if ($this->keys) {
// Update primary keys with new values
foreach (array_keys($this->keys) as $_field) {
$this->keys[$_field] = $this->fields[$_field];
}
}
if (method_exists($this, 'afterSave')) {
// Execute afterSave event
$this->afterSave();
}
}