示例#1
0
function db_fetch($query, $placeholders = array())
{
    $data = array();
    $result = db_prepere($query, $placeholders);
    while ($row = mysql_fetch_assoc($result)) {
        $data[] = $row;
    }
    return $data;
}
示例#2
0
function entity_create($name)
{
    $id_field = $name[0] . 'id';
    $fields = function_exists("{$name}_fields") ? call_user_func_array("{$name}_fields", array()) : array();
    db_prepere('DROP TABLE IF EXISTS `' . $name . '`');
    db_prepere('CREATE TABLE `' . $name . '` (`' . $id_field . '` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `delete` int DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8');
    foreach ($fields as $field => $options) {
        $sql_field = '';
        switch ($options['type']) {
            case 'text':
                $sql_field = 'varchar(255) CHARACTER SET utf8 DEFAULT NULL';
                break;
            case 'textarea':
                $sql_field = 'text CHARACTER SET utf8 DEFAULT NULL';
                break;
            case 'int':
                $sql_field = 'int DEFAULT NULL';
                break;
            case 'bool':
                $sql_field = 'tinyint DEFAULT NULL';
                break;
            case 'serialize':
                $sql_field = 'text CHARACTER SET utf8 DEFAULT NULL';
                break;
        }
        if (!empty($sql_field)) {
            db_prepere('DROP TABLE IF EXISTS `field_' . $name . '_' . $field . '`');
            db_prepere('CREATE TABLE `field_' . $name . '_' . $field . '` (`' . $id_field . '` int NOT NULL, `data` ' . $sql_field . ') ENGINE=InnoDB DEFAULT CHARSET=utf8');
        }
    }
}