{"id":20929150,"url":"https://github.com/quickstartlibs/db","last_synced_at":"2026-05-04T13:32:51.884Z","repository":{"id":57052833,"uuid":"41853186","full_name":"QuickStartLibs/DB","owner":"QuickStartLibs","description":"Stash Queries - A thin and simple yet elegant database abstraction layer around PDO.","archived":false,"fork":false,"pushed_at":"2018-04-17T13:45:24.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-22T11:39:00.732Z","etag":null,"topics":["database","injection","mysql","pdo","pdo-replacement","pdo-wrapper","persistent-connections","php","queries","query-builder","querying","sql","stash-queries","stash-query"],"latest_commit_sha":null,"homepage":"http://skyfirephp.com/Database","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/QuickStartLibs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-03T10:05:22.000Z","updated_at":"2022-06-10T12:30:18.000Z","dependencies_parsed_at":"2022-08-24T05:10:15.962Z","dependency_job_id":null,"html_url":"https://github.com/QuickStartLibs/DB","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/QuickStartLibs/DB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuickStartLibs%2FDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuickStartLibs%2FDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuickStartLibs%2FDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuickStartLibs%2FDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QuickStartLibs","download_url":"https://codeload.github.com/QuickStartLibs/DB/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QuickStartLibs%2FDB/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273529562,"owners_count":25121830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","injection","mysql","pdo","pdo-replacement","pdo-wrapper","persistent-connections","php","queries","query-builder","querying","sql","stash-queries","stash-query"],"created_at":"2024-11-18T21:17:32.932Z","updated_at":"2026-05-04T13:32:51.878Z","avatar_url":"https://github.com/QuickStartLibs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stash Queries\n\n\u003e Stash Queries is an eloquent and expressive PHP library that simplifies database interactions.\n\nIt acts as a lightweight wrapper around PHP's native PDO (PHP Data Objects) extension, providing a fluent API to easily execute `SELECT`, `INSERT`, `UPDATE`, and `DELETE` operations using your actual SQL files.\nOriginally developed as the *DB* service for the Skyfire PHP framework, this library is specifically designed as a native PDO replacement rather than a full Object-Relational Mapper (ORM).\n\n_Note: Currently, Stash Queries supports MySQL and PostgreSQL databases. Support for additional database are up for request._\n\n## Requirements\n\n- PHP 5.6 or higher\n- `PDO_MYSQL` PHP extension\n\n*(Note: PHP 5.6 is the minimum required version for security and modern language features.)*\n\n## Code Examples\n\n```php\n// setting the DB display encoding type (if needed)\nFixCollation::charset('utf-8', FixCollation::TEXT_HTML);\n\n// setting Database credentials\nDB::define('stash_dir',   getcwd()); // or dirname(__FILE__)\nDB::define('host',       'localhost');\nDB::define('dbname',     'test_db1');\nDB::define('dbuser',     'root');\nDB::define('dbpassword', '');\n\n\n// SQL select query (with prepare variables)\n$prepare = array\n(\n    'label' =\u003e 'test'\n);\n$data = DB::select('get.HomeTextByLabel')-\u003eprepare($prepare);\nvar_dump($data);\n\n\n// SQL simple select query\n$data = DB::select('get.AllHomeTextData')-\u003eexecute();\nvar_dump($data);\n\n\n// raw SQL query (with prepare variables)\n$data = DB::query('SELECT * FROM test WHERE data IS NOT NULL AND id \u003e :count AND data != :text', array\n(\n    ':id'   =\u003e 10,\n    ':text' =\u003e 'test'\n))-\u003eexecute();\nvar_dump($data);\n\n\n// displays the prepare update statement in plain text (ideal for debugging queries)\n$query = DB::update('PostfromTestById')-\u003etext($prepare);\necho $query;\n```\n\n## Injections\n\nYou can securely inject dynamic variables directly into your queries (e.g., table names or column fields) when standard PDO bindings cannot be used:\n\n```php\n$data = DB::select('get.fieldData.byId')-\u003einject(array\n(\n    'field' =\u003e $data-\u003efield,\n    'table' =\u003e $table_name\n))-\u003eprepare(array('id' =\u003e (int) $record-\u003eid));\n```\n\n## Persistent Connections\n\nTo enable persistent database connections for all queries, define the `persistent` configuration setting as follows:\n\n```php\nDB::define('persistent', TRUE);\n// DB::define('persistent', 'yes');\n```\n\nYou can use either the boolean `TRUE` or the string `'yes'` to enable this feature.\n\n## Creating Query Folders\n\nIf you are unsure whether your SQL query folders exist, you can call the following function to create them automatically. It returns `FALSE` if no directories were created, or an integer representing the number of directories created (e.g., `4`).\n\n```php\nDB::createQueryDirectories();\n```\n\n**Note:** Ensure you place this function call after all `DB::define()` configurations.\n\n## Quickly Create a Database\n\nYou can conveniently create a new database if it doesn't already exist:\n\n```php\nDB::createNotExist('database_name');\n```\n\n**Note:** Ensure you place this function call after all `DB::define()` configurations.\n\n## Installation\n\n**Manual Installation:**\nTo include the library manually, simply require the `StashQueries.php` file in your project:\n\n```php\nrequire_once 'DB/StashQueries.php';\n```\n\n**Via Composer:**\nAlternatively, you can install the library via Composer by adding `skyfirephp/db` to the `require` section of your `composer.json` file:\n\n```json\n{\n    \"require\": {\n        \"skyfirephp/db\": \"dev-master\"\n    }\n}\n```\n\n## License\n\nStash Queries is open-sourced software licensed under the [MIT License](http://opensource.org/licenses/MIT).\n\nCopyright 2015-2017 [Travis van der Font](http://travisfont.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquickstartlibs%2Fdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquickstartlibs%2Fdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquickstartlibs%2Fdb/lists"}