承接 yoramdelangen/laravel-pdo-odbc 相关项目开发

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

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

yoramdelangen/laravel-pdo-odbc

Composer 安装命令:

composer require yoramdelangen/laravel-pdo-odbc

包简介

PDO ODBC/Snowflake integration for Laravel framework. Support ODBC and native PDO Snowflake.

README 文档

README

Enjoying this project?

Buy us a coffee

This repository provides seamless integration of ODBC/Snowflake with Laravel Eloquent. It aims to create a comprehensive ODBC package for Laravel, while also functioning as a standalone solution.

Unlike the odbc_* functions, this package utilizes the PDO class, resulting in smoother and more convenient integration with Eloquent.

The primary goal of this package is to offer a standardized approach to connect with an ODBC connection. It supports custom grammars and schemas to accommodate various ODBC connections, such as Snowflake.

How to Install

Before proceeding, ensure that you have PHP version 8.x installed on your system.

To add the package to your project, run the following command:

composer require yoramdelangen/laravel-pdo-odbc

By default, the package will be automatically registered through the package:discover command.

Alternatively, you can manually register the service provider in the app.php file:

'providers' => [
  // ...
  LaravelPdoOdbc\ODBCServiceProvider::class,
];

If you intend to use the snowflake_pdo PHP extension, please follow the installation guide provided here to set it up.

Starting from version 1.2.0, the package includes support for snowflake_pdo, but it will still function without the Snowflake extension (via ODBC).

Configuration

The available driver flavors are:

  • ODBC (generic)
  • Snowflake (via ODBC and native through PHP extension)
  • ...

Snowflake Specific environment variables

You have the option to customize the Snowflake driver using the following parameters:

# When set to `false`, column names are automatically uppercased.
SNOWFLAKE_COLUMNS_CASE_SENSITIVE=false

# When set to `true`, column names are wrapped in double quotes and their
# case is determined by the input.
SNOWFLAKE_COLUMNS_CASE_SENSITIVE=true

Snowflake Query Grammar options

When using the Snowflake flavour, the query grammar compiles LIKE clauses as ILIKE by default (case-insensitive). You can disable this behavior per connection:

'snowflake_pdo' => [
    // ...
    'options' => [
        'use_ilike' => false,
    ],
],

Usage

Configuring the package is straightforward:

Add a Database Configuration to database.php

Starting from version 1.2, we recommend using the native Snowflake extension instead of ODBC, but we'll keep supporting it.

'snowflake_pdo' => [
    'driver' => 'snowflake_native',
    'account' => '{account_name}.eu-west-1',
    'username' => '{username}',
    'password' => '{password}',
    'database' => '{database}',
    'warehouse' => '{warehouse}',
    'schema' => 'PUBLIC', // change it if necessary.
    'options' => [
        // Required for Snowflake usage
        \PDO::ODBC_ATTR_USE_CURSOR_LIBRARY => \PDO::ODBC_SQL_USE_DRIVER
    ]
],

You have multiple ways to configure the ODBC connection:

  1. Simple configuration using DSN only:

    'odbc-connection-name' => [
        'driver' => 'odbc',
        'dsn' => 'OdbcConnectionName', // odbc: will be prefixed
        'username' => 'username',
        'password' => 'password'
    ]

    or, if you don't have a datasource configured within your ODBC Manager:

    'odbc-connection-name' => [
        'driver' => 'odbc',
        'dsn' => 'Driver={Your Snowflake Driver};Server=snowflake.example.com;Port=443;Database={DatabaseName}',
        'username' => 'username',
        'password' => 'password'
    ]

    Note: The DSN Driver parameter can either be an absolute path to your driver file or the name registered within the odbcinst.ini file/ODBC manager.

  2. Dynamic configuration:

    'odbc-connection-name' => [
        'driver' => 'snowflake',
        // please change this path accordingly your exact location
        'odbc_driver' => '/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib',
        // 'odbc_driver' => 'Snowflake path Driver',
        'server' => 'host.example.com',
        'username' => 'username',
        'password' => 'password',
        'warehouse' => 'warehouse name',
        'schema' => 'PUBLIC', // most ODBC connections use the default value
    ]

    All fields, except for driver, odbc_driver, options, username, and password, will be dynamically added to the DSN connection string.

    Note: The DSN odbc_driver parameter can either be an absolute path to your driver file or the name registered within the odbcinst.ini file/ODBC manager.

Eloquent ORM

You can use Laravel, Eloquent ORM, and other Illuminate components as usual.

# Facade
$books = DB::connection('odbc-connection-name')
            ->table('books')
            ->where('Author', 'Abram Andrea')
            ->get();

# ORM
$books = Book::where('Author', 'Abram Andrea')->get();

Troubleshooting and more info

We have documented all weird behavious we encountered with the ODBC driver for Snowflake. In case of trouble of weird messages, checkout the following links:

Customization

yoramdelangen/laravel-pdo-odbc 适用场景与选型建议

yoramdelangen/laravel-pdo-odbc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 280.71k 次下载、GitHub Stars 达 38, 最近一次更新时间为 2020 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 yoramdelangen/laravel-pdo-odbc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 yoramdelangen/laravel-pdo-odbc 我们能提供哪些服务?
定制开发 / 二次开发

基于 yoramdelangen/laravel-pdo-odbc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 280.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 38
  • 点击次数: 31
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 38
  • Watchers: 5
  • Forks: 32
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-26