{"id":15295773,"url":"https://github.com/alexsasharegan/database_lib","last_synced_at":"2026-01-05T18:04:22.798Z","repository":{"id":56944800,"uuid":"66159667","full_name":"alexsasharegan/Database_lib","owner":"alexsasharegan","description":"A dependency free, light PHP mysqli library to properly handle errors, connections, and make getting data simple and DRY.","archived":false,"fork":false,"pushed_at":"2017-04-02T14:46:52.000Z","size":255,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T03:52:24.676Z","etag":null,"topics":["database","dbal","mysql","mysql-database","php"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/alexsasharegan/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/alexsasharegan.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":"2016-08-20T17:36:20.000Z","updated_at":"2016-11-18T04:35:38.000Z","dependencies_parsed_at":"2022-08-21T02:40:20.196Z","dependency_job_id":null,"html_url":"https://github.com/alexsasharegan/Database_lib","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsasharegan%2FDatabase_lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsasharegan%2FDatabase_lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsasharegan%2FDatabase_lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexsasharegan%2FDatabase_lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexsasharegan","download_url":"https://codeload.github.com/alexsasharegan/Database_lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394767,"owners_count":20608123,"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","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","dbal","mysql","mysql-database","php"],"created_at":"2024-09-30T18:08:08.392Z","updated_at":"2026-01-05T18:04:17.746Z","avatar_url":"https://github.com/alexsasharegan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Database\n[![Latest Stable Version](https://poser.pugx.org/alexsasharegan/database/v/stable)](https://packagist.org/packages/alexsasharegan/database)\n[![Total Downloads](https://poser.pugx.org/alexsasharegan/database/downloads)](https://packagist.org/packages/alexsasharegan/database)\n[![Latest Unstable Version](https://poser.pugx.org/alexsasharegan/database/v/unstable)](https://packagist.org/packages/alexsasharegan/database)\n[![License](https://poser.pugx.org/alexsasharegan/database/license)](https://packagist.org/packages/alexsasharegan/database)\n\nPHP MySQL utilities to properly handle errors, connections, and make getting data simple and DRY.\n\n- - - -\n\n\n## Installation\n\nWith **Composer**:\n\n```shell\ncomposer require alexsasharegan/database\n```\n\nThen require in the vendor autoloader:\n```php\n\u003c?php\n\nrequire_once 'path/to/vendor/autoload.php';\n```\n\n## Usage\n\n### Static Methods\n\nCalling `Database::connect( [ string $configFile = './database.json', array $options = [] ] )` without any arguments will look for a configuration file called `database.json` file in the calling file's directory. To make use of this default behavior, place your `database.json` next to your php file. If your config file exists elsewhere, pass in the path as the first argument.\n\nAn example config file is included in the project. Just change the name from `database.example.json` to `database.json` and move it next to your calling php file. Here is the example config:\n\n```php\n\u003c?php\n\n// library defaults\n$connectionOptions = [\n    'DB_HOST'     =\u003e '127.0.0.1',\n    'DB_NAME'     =\u003e 'test',\n    'DB_PORT'     =\u003e '3306',\n    'DB_CHARSET'  =\u003e 'utf8',\n    'DB_USERNAME' =\u003e 'admin',\n    'DB_PASSWORD' =\u003e 'admin',\n];\n\n// library defaults\n$pdoOptions = [\n\tPDO::ATTR_ERRMODE            =\u003e PDO::ERRMODE_EXCEPTION,\n\tPDO::ATTR_DEFAULT_FETCH_MODE =\u003e PDO::FETCH_ASSOC,\n\tPDO::ATTR_EMULATE_PREPARES   =\u003e FALSE,\n\tPDO::ATTR_STRINGIFY_FETCHES  =\u003e FALSE,\n];\n\n$mySQL = new \\Database\\MySQL($connectionOptions, $pdoOptions);\n```\n\nSome other static methods:\n\n```php\n\u003c?php\n\nuse Database\\MySQL;\n\n# Takes a MySQL-formatted date string and returns a string file path\nMySQL::SQLDateToPath( string $SQLDate );\n# example\necho MySQL::SQLDateToPath( '2016-09-06 14:02:26' );\n# Outputs: '2016/09/06'\n\n# Returns a MySQL-formatted timestamp\necho MySQL::now();\n# Outputs: '2016-09-06 14:04:15';\n\n```\n\n### Instance Methods\n\n#### QUERY\n\n```php\n\u003c?php\n$mySQL = new \\Database\\MySQL($connectionOptions, $pdoOptions);\n\n# use a try/catch block to handle a bad query\ntry {\n  $mySQL-\u003eselect(['firstName', 'lastName'])\n        -\u003efrom('users')\n        -\u003ewhere('id', 'in', [1,2,3])\n        # we can chain methods together here\n        -\u003emap(\n        # this can be any callable type ( will be called with each row )\n        # closures let us 'use' vars from parent scope\n        # be wary of when you need to pass by reference using \u0026\n        function ( array $resultRow ) \n        {\n            $users[] = new User($resultRow); # the $resultRow is an associative array\n        }\n    );\n} catch ( Exception $e ) {\n  # insert some custom error handling here\n  exit( $e );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexsasharegan%2Fdatabase_lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexsasharegan%2Fdatabase_lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexsasharegan%2Fdatabase_lib/lists"}