Ting:一个轻量级的数据映射器

3.9.1 2024-07-19 14:35 UTC

README

Ting 是 PHP 的简单数据映射器实现。它在 MySQL 和 PostgreSQL 上运行,并采用 Apache-2.0 许可证。

它具有一些独特的特性和设计选择

  • 纯 PHP 实现(无 PDO,无 XML)
  • 无抽象层:你说的是你的关系数据库管理系统的语言
  • 快速,内存消耗低
  • 简单易用,易于扩展

你可以阅读以下示例,或访问 文档 或查看更多 示例

通过 ID 获取对象

<?php
$cityRepository = $services->get('RepositoryFactory')->get('\sample\src\model\CityRepository');

## Retrieve city by id :
$city = $cityRepository->get(3);

简单查询

<?php
# This query supports the same syntax as prepared statements, but it'll be a regular query
$query = $cityRepository->getQuery(
    "select cit_id, cit_name, c.cou_code, cit_district, cit_population, last_modified,
        co.cou_code, cou_name, cou_continent, cou_region, cou_head_of_state
    from t_city_cit as c
    inner join t_country_cou as co on (c.cou_code = co.cou_code)
    where co.cou_code = :code limit 3"
);

$collection = $query->setParams(['code' => 'FRA'])->query();

foreach ($collection as $result) {
    var_dump($result);
    echo str_repeat("-", 40) . "\n";
}

预处理语句

<?php
// Simple query :
$query = $cityRepository->getQuery('SQL Statement');
// Prepared statement :
$query = $cityRepository->getPreparedQuery('SQL Statement');

aura/sqlquery 提供的QueryBuilder

<?php
$queryBuilder = $cityRepository->getQueryBuilder($cityRepository::QUERY_SELECT);
$queryBuilder
    ->cols(['cit_id', 'cit_name as name'])
    ->from('t_city_cit');
$query = $cityRepository->getQuery($queryBuilder->getStatement());

更多