This repository contains a PHP database access and query-builder layer extracted from HugaShop, an e-commerce / CRM platform by Andri Huga. The code lives under hugashop/crm/Api/ and is meant to work with MySQL via the mysqli extension.
Database— low-level database access: connection management, parameterized queries via a placeholder syntax (?,?@for lists,?%for key/value sets), table-name prefixing (__tablename→ configured prefix), escaping, and optional automaticCREATE TABLE/ALTER TABLEwhen a query fails because a table or column is missing. Also includes dump and restore helpers for prefixed tables.DatabaseQuery— a fluent query builder forSELECT,INSERT,UPDATE, andDELETE, includingWHERE(withAND/OR),LEFT JOINagainst other API model classes,ORDER BY, pagination (limit), aggregates (count,sum), and convenience methods such asgetOne,getList,getCount,add,updateOne, anddeleteOne. Table metadata (fields, joins) is expected to be defined on extending classes via a static$tabledefinition pattern used in the full HugaShop codebase.Config— loadsconfig.yamlfrom the CRM directory (next toApi/), merges runtime paths and URLs, and exposes settings throughConfig::get().Helper— shared utilities (caching, string/slug helpers, tokens, normalization of joined row data, etc.). Note: this class references other HugaShop types (Settings,Request, and others) that are not included in this repository; it is intended to run as part of the full project or after you provide compatible stubs.
hugashop/crm/
├── Api/
│ ├── Config.php
│ ├── Database.php
│ ├── DatabaseQuery.php
│ └── Helper.php
└── config_default.yaml # example / template settings (copy to config.yaml)
- PHP 8.1+ (uses union types and other modern syntax).
- MySQL (or MariaDB) and the mysqli extension.
symfony/yamlforConfig(and YAML usage inHelperwhere applicable).
Helper.php additionally declares dependencies used in the full application (for example Illuminate Support, Symfony Cache, Google reCAPTCHA, jenssegers/agent). If you use Helper as-is, install the same packages via Composer in your parent project, or trim unused methods.
- Copy
hugashop/crm/config_default.yamltohugashop/crm/config.yaml. - Fill in at least the
databasesection:server,user,password,name, and optionallyprefix,charset,sql_mode. - Set
saltand other keys as required by your deployment.
Config resolves paths assuming a typical HugaShop tree (CRM folder, project root with templates/, public/, var/, etc.). Adjust or bootstrap Config if your directory layout differs.
All PHP classes in Api/ use the namespace HugaShop\Api.
Extend DatabaseQuery in your own model classes, define static $table (name, fields, joins), then chain calls — for example: select(), where(...), leftJoin(...), getResult() / getResults(), or use Database::placehold() / query() for raw SQL.
See inline documentation and examples in DatabaseQuery.php (e.g. where, leftJoin, order).
Original headers credit Andri Huga and the HugaShop project. If you redistribute or fork, preserve author and license notices from the upstream project when applicable.