danek/grimoire-db

Grimoire 是一个用于在数据库中简单处理数据的 PHP 库。

dev-main 2024-09-04 20:34 UTC

This package is auto-updated.

Last update: 2024-09-04 20:34:15 UTC


README

https://repository-images.githubusercontent.com/677257963/b1803baf-c64a-4975-98c9-9ea5f5425cfa

Grimoire 是一个用于在数据库中简单处理数据的 PHP 库。最有趣的功能是处理表关系非常简单。整体性能也非常重要,Grimoire 实际上可以比原生驱动运行得更快。

内容

要求

  • PHP 7.1+
  • 仅支持 MySQL 数据库

安装

composer require danek/grimoire-db

用法

<?php

$connection = new \Mysqli(...);
$config = Grimoire\Config::build($connection);
$software = new Grimoire\Database($config);

foreach ($software->table('application')->order("title") as $application) { // get all applications ordered by title
    echo $application['title'] . "\n"; // print application title
    echo $application->ref('author')['name'] . "\n"; // print name of the application author
    foreach ($application->related('application_tag') as $application_tag) { // get all tags of $application
        echo $application_tag->ref('tag')['name'] . "\n"; // print the tag name
    }
}