javanile/hamper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

javanile/hamper

Composer 安装命令:

composer require javanile/hamper

包简介

Developer friendly database library for vtiger

README 文档

README

Developer friendly database library for vtiger. Hamper improove the code quality and the readbility of your PHP code around database access and manipulation.

Why I use it?

Here is a list of compelling reasons to use it

  • Avoid old-style loop over results.
  • Use by default associative array for fields.

Installation

You can install the package via composer:

composer require javanile/hamper

Usage

You simply get your $hdb object to access on database

require_once 'vendor/autoload.php';

use Javanile\Hamper\Hamper;

$hdb = Hamper::getInstance();

📃 Documentation

😎 The documentation lists all the functions you can use to make the code simple and easy to read.

The access you have on the data inside the database is based on extraction methods that return array and that you can easily manipulate with foreach. Use the functions well because they allow you to take a single record or a list of records or all the values of a column. Before starting to use it, read the list of functions carefully, and you will automatically use the best one based on the context. For each function you are also presented, the "😿 Legacy", the version of the old style Vtiger code you can replace with Hamper functions, comparing them, and you will realize how Hamper improves your work.

All Functions

The following methods are used to manipulate records into database

The following methods are used to manipulate database tables and fields

Execute query

Executes the given parametric query

Usage

$hdb->query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->query(...) function

[back to top ☝]

Get a single record

Fetches the next row from the result set rows by the given parametric query.

Usage

$hdb->fetch($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->fetch(...) function

[back to top ☝]

Get a list of records

Returns an array containing all of the result set rows by the given parametric query.

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->fetchAll(...) function

[back to top ☝]

Get a value from record

Fetches the next row from the result set rows by the given parametric query.

Usage

$hdb->fetchValue($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

$crmId = $hdb->fetchValue("SELECT crmid FROM vtiger_crmentity WHERE setype=? AND deleted=0", [$module]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->fetchValue(...) function

$adb = \PearDatabase::getInstance();
$result = $adb->pquery("SELECT tabid FROM vtiger_tab WHERE name=?", [$setype]);
$tabId = $adb->query_result($result, 0, "tabid");

[back to top ☝]

Get value by key column

Execute a query to check if record with specific key and value exists.

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->value(...) function

[back to top ☝]

Check if record exists

Execute a query to check if record with specific key and value exists.

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->exists(...) function

[back to top ☝]

Insert a record

Inserts the given record within the selected table.

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->insert(...) function

[back to top ☝]

Get last ID

Return last insert ID value for the selected table.

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->lastInsertId(...) function

[back to top ☝]

Update a single record

Updates the given record with the given data.

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->update(...) function

[back to top ☝]

Delete a single record

Deletes the given record within the given table.

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

// Execute simple query
$hdb->query("SET NAMES utf8");
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);

😿 Legacy

Please, replace this kind of legacy code with the $hdb->delete(...) function

[back to top ☝]

Create new table

Usage

query($sql, $params = [], $options = [])

Examples

This method is useful to handle this situations

😿 Legacy

Please, replace this kind of legacy code with the $hdb->create(...) function

[back to top ☝]

Changelog

Please see CHANGELOG for more information on what has changed recently.

Testing

$ make install
$ make tdd take=tests/HamperDatabaseTest.php 

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email bianco@javanile.org instead of using the issue tracker.

Socialware

We highly appreciate if you create a social post on Twitter with following button

Share on Twitter

Credits

This project exists thanks to all the people who contribute.

Support us

Javanile is a community project agency based in Sicily, Italy. You'll find an overview of all our projects on our website.

Does your business depend on our contributions? Reach out us on Patreon.

License

The MIT License (MIT). Please see License File for more information.

javanile/hamper 适用场景与选型建议

javanile/hamper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 javanile/hamper 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-17