danmarinescu/db-layer

提供无需模型即可轻松访问数据库的Zend Framework 2 DB Layer,它返回一个ResultSet

1.1 2015-07-12 02:33 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:49:17 UTC


README

构建状态 Scrutinizer 代码质量 构建状态 代码覆盖率 最新稳定版本 总下载量 最新不稳定版本 许可证 DbLayer - README

名称:DbLayer 版本:1.0 发布日期:2015-07-11 作者:Dan Marinescu

版权 (c) 2015: Dan Marinescu

描述:DbLayer 是一个PHP类集合,用于在ZendFramework2中动态查询数据库,无需模型或实体等扩展。

层使用

Get intsnace of a DB Table :

    $tableInstance = $this->getServiceLocator()->get('DbLayerService')->get($tableName);

Method's provided by the $tableInstance :
    Select :
    $tableInstance->select()->fetchAll();
        Returning all records from a DB Table.

    $tableInstance->select()->fetchOne();
        Returning a single record from a DB Table.

    $tableInstance->select()->fetchPaginated($paginator);
        Returning paginated records from a DB Table ready to use with ZF2 pagination view helper.


    $tableInstance->insert($data);

    $tableInstance->update($data, $where);

    $data = array(
        'TableColumn' => 'TableValue',
        'TableColumn2' => 'TableValue2',
    );

    $tableInstance->delete($where);

    Layer instance methods :

        select($where) accepts an array with WHERE predicate conditions
            $where = array(
                'id = ?' => $id
            );

        join($join) accepts an array for joining other tables
            $join = array(
                array(
                    'table_name' => 'JoinedTable',
                    'join_condition' => 'Table.Id = JoinedTable.TableId',
                    'columns' => array('JoinedTableColumn', 'AliasedTableName' => 'JoinedTableColumn2'),
                    'join' => 'left',
                ),
                array(
                    'table_name' => 'JoinedTable',
                    'join_condition' => 'Table.Id = TableAliasName.TableId',
                    'columns' => array('JoinedTableAliasNameColumn', 'AliasedTableName' => 'JoinedTableAliasNameColumn2'),
                    'join' => 'left',
                    'alias' => 'TableAliasName'
                ),
            );

        limit(2) limiting results returned to 2

        order($order) ordering results
            $order = array(
                'Table.Id' => 'ASC',
                'JoinedTable.TableId' => 'DESC',
            );

        having($having)

        group($group)

主要功能

安装:composer require danmarinescu/db-layer

许可证:版权 (C) 2015 Dan Marinescu

DbLayer is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

DbLayer is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

============================================================