本文整理汇总了PHP中POD::fieldType方法的典型用法代码示例。如果您正苦于以下问题:PHP POD::fieldType方法的具体用法?PHP POD::fieldType怎么用?PHP POD::fieldType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类POD
的用法示例。
在下文中一共展示了POD::fieldType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
if (!isset($this->structure) || empty($this->structure) || !is_array($this->structure)) {
return false;
}
/// TO DO : implementing create method by structure
$sql = "CREATE " . $this->table . " (" . CRLF;
foreach ($this->structure as $field => $attributes) {
$sql .= $field;
$type = $length = $isNull = $default = "";
foreach ($attributes as $attr => $value) {
if ($attr == "type") {
// Type casting
$type = POD::fieldType($type);
}
if ($attr == "isNull") {
$isNull = $value;
}
if ($attr == "default") {
$default = $value;
}
}
$sql .= ' ' . $type . (!empty($length) ? "(" . $length . ")" : "") . ' ' . ($default ? 'DEFAULT ' . (in_array($type, array("integer", "timestamp", "float")) ? $default : '"' . $default . '"') : "") . ' ' . ($isNull ? "NULL" : "NOT NULL") . CRLF;
}
$sql .= ")";
return POD::execute($sql);
}
示例2: create
public function create()
{
if (!isset($this->structure) || empty($this->structure) || !is_array($this->structure)) {
return false;
}
/// TO DO : implementing create method by structure
$this->_called = true;
$sql = "CREATE TABLE " . $this->_getTableName() . " (" . CRLF;
$keys = array();
foreach ($this->structure as $field => $attributes) {
$type = $length = $isNull = $default = "";
foreach ($attributes as $attr => $value) {
if ($attr == "type") {
// Type casting
$type = POD::fieldType($value);
}
if ($attr == "isNull") {
$isNull = $value;
}
if ($attr == "default") {
$default = $value;
}
if ($attr == "length") {
$length = intval($value);
}
if ($attr == "autoincrement") {
$ai = $value;
}
if ($attr == "index" && $value == true) {
array_push($keys, $field);
}
}
$sql .= $field;
$sql .= ' ' . $type . (!empty($length) ? "(" . $length . ")" : "") . ' ' . ($default ? 'DEFAULT ' . (in_array($type, array("integer", "timestamp", "float")) ? $default : '"' . POD::escapeString($default) . '"') : "") . ' ' . ($isNull ? "NULL" : "NOT NULL") . (isset($ai) && $ai == true ? ' AUTO INCREMENT' : '') . ',';
}
$sql = rtrim($sql, ",");
if (is_array($this->option) && array_key_exists('primary', $this->option)) {
$sql .= ', PRIMARY KEY (' . implode(',', $this->option['primary']) . ')';
}
foreach ($keys as $key) {
$sql .= ', KEY (' . POD::escapeString($key) . ')';
}
$sql .= ")";
$result = POD::execute($sql);
$this->_manage_pool_stack();
return $result;
}