承接 mapado/mysql-doctrine-functions 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mapado/mysql-doctrine-functions

最新稳定版本:v1.1.3

Composer 安装命令:

composer require mapado/mysql-doctrine-functions

包简介

MySQL Function for Doctrine : RAND(), ROUND() DATE(), DATE_FORMAT()...

README 文档

README

This library provides you MySQL functions for Doctrine2.

At the moment are supported

  • RAND
  • ROUND
  • DATE
  • DATE_FORMAT

Feel free to fork and add other functions.

Installation

Get the package

With composer

composer require mapado/mysql-doctrine-functions

Add the classes to your configuration

$config = new \Doctrine\ORM\Configuration();
$config->addCustomStringFunction('rand', \Mapado\MysqlDoctrineFunctions\DQL\MysqlRand::class);
$config->addCustomStringFunction('round', \Mapado\MysqlDoctrineFunctions\DQL\MysqlRound::class);
$config->addCustomStringFunction('date', \Mapado\MysqlDoctrineFunctions\DQL\MysqlDate::class);
$config->addCustomStringFunction('date_format', \Mapado\MysqlDoctrineFunctions\DQL\MysqlDateFormat::class);

$em = EntityManager::create($dbParams, $config);

You can of course pick just the functions you need.

Use with Symfony

If you install the library in a Symfony application, you can add this in your config.yml file (doctrine.yaml file if you use symfony flex)

# app/config/config.yml
doctrine:
    orm:
        # ...
        entity_managers:
            default:
                # ...
                dql:
                    numeric_functions:
                        rand:        'Mapado\MysqlDoctrineFunctions\DQL\MysqlRand'
                        round:       'Mapado\MysqlDoctrineFunctions\DQL\MysqlRound'
                    datetime_functions:
                        date:        'Mapado\MysqlDoctrineFunctions\DQL\MysqlDate'
                        date_format: 'Mapado\MysqlDoctrineFunctions\DQL\MysqlDateFormat'
                    # ... add all functions you need

Usage

You can now use the functions in your DQL Query

$query = 'SELECT RAND(), ROUND(123.45) 
        FROM ...
    ';
$em->createQuery($query);

统计信息

  • 总下载量: 268.6k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 44
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 44
  • Watchers: 13
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-28