{"id":20161731,"url":"https://github.com/asdfdotdev/cl_database","last_synced_at":"2026-04-15T10:36:00.572Z","repository":{"id":81365188,"uuid":"88233258","full_name":"asdfdotdev/cl_database","owner":"asdfdotdev","description":"PHP database class","archived":false,"fork":false,"pushed_at":"2020-06-27T14:56:54.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T02:43:32.133Z","etag":null,"topics":["database","mariadb","mysql","php7","phpunit-6","postgresql","sqlserver"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asdfdotdev.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-14T04:37:15.000Z","updated_at":"2019-04-06T19:18:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"334e80d5-439f-4746-acfa-2ad7a378dd31","html_url":"https://github.com/asdfdotdev/cl_database","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/asdfdotdev/cl_database","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asdfdotdev%2Fcl_database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asdfdotdev%2Fcl_database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asdfdotdev%2Fcl_database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asdfdotdev%2Fcl_database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asdfdotdev","download_url":"https://codeload.github.com/asdfdotdev/cl_database/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asdfdotdev%2Fcl_database/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259539025,"owners_count":22873332,"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","mariadb","mysql","php7","phpunit-6","postgresql","sqlserver"],"created_at":"2024-11-14T00:20:26.593Z","updated_at":"2026-04-15T10:35:55.545Z","avatar_url":"https://github.com/asdfdotdev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChristopherL Database Class\n\nThe cl_database() class endeavors to make it easy to add database support to PHP scripts for a variety of needs by abstracting query construction.\n\n* Supports MySQL/MariaDB, PostgreSQL, and SQL Server\n* Uses prepared statements to prevent SQL injection\n* Logs all queries for reference\n* Automatically applies table prefix to statements\n* Works in PHP 5.6-7.0\n\n## Examples\n\ncl_database class supports standard database query actions with a simplified array syntax.\n\n### Connecting to server:\n\n```\n$db = new \\ChristopherL\\Database([\n    'server' =\u003e 'mysql',\n    'host' =\u003e '127.0.0.1',\n    'username' =\u003e 'dbuser,\n    'password' =\u003e '123456,\n    'database' =\u003e 'mydb',\n    'port' =\u003e 3306,\n    'prefix' =\u003e 'tbl_'\n]);\n```\n\n### Querying connected server:\n\n#### Selecting data:\n\n```\n$db-\u003eselect(\n    'my_table',\n    [\n        'my_table' =\u003e ['string_column'],\n        'my_other_table' =\u003e ['string_column{my_alias}']\n    ],\n    [\n        'AND' =\u003e [\n            'my_table' =\u003e [\n                'date_column[\u003e=]' =\u003e date('Y-m-d'),\n            ],\n            'my_other_table' =\u003e [\n                'date_column[\u003e=]' =\u003e date('Y-m-d')\n            ]\n        ]\n    ],\n    [\n        '[\u003e]my_other_table' =\u003e ['fk_column', 'k_column']\n    ]\n);\n```\n\nResulting query\n\n```\nSELECT  my_table.string_column, my_other_table.string_column AS my_alias \nFROM my_table \n\tLEFT JOIN my_other_table ON (my_table.fk_column = my_other_table.k_column)  \nWHERE my_table.date_column \u003e= '2017-05-03'\n\tAND my_other_table.date_column \u003e= '2017-05-03'\n```\n\n#### Inserting data:\n\n```\n$db-\u003einsert(\n    'my_table',\n    [\n        [\n            'number_column' =\u003e 500,\n            'string_column' =\u003e 'some text',\n            'boolean_column' =\u003e 1,\n            'date_column' =\u003e date('Y-m-d'),\n            'time_column' =\u003e date('H:i:s')\n        ],\n        [...]\n    ]\n);\n```\n\nResulting query\n\n```\nINSERT INTO my_table(number_column, string_column, boolean_column, date_column, time_column) \nVALUES(500, 'some text', 1, '2017-05-03', '01:49:31')\n```\n\n\u003e Multiple records can be inserted by including multiple column =\u003e value arrays.\n\n#### Updating data:\n\n```\n$db-\u003eupdate(\n    'my_table',\n    [\n        'string_column' =\u003e 'new value',\n    ],\n    [\n        'AND' =\u003e [\n            'my_table' =\u003e [\n                'date_column[\u003e]' =\u003e date('Y-m-d'),\n                'boolean_column[=]' =\u003e 1\n            ]\n        ]\n    ]\n);\n```\n\nResulting query\n\n```\nUPDATE my_table \nSET string_column = 'new value'\nWHERE my_table.date_column \u003e= '2017-05-03' AND my_table.boolean_column = 1;\n```\n\n#### Deleting data:\n\n```\n$db-\u003edelete(\n    'my_table',\n    [\n        'AND' =\u003e [\n            'my_table' =\u003e [\n                'date_column[\u003e]' =\u003e date('Y-m-d'),\n                'boolean_column[=]' =\u003e 1\n            ]\n        ]\n    ]\n);\n```\n\nResulting query\n\n```\nDELETE FROM my_table WHERE my_table.date_column \u003e= '2017-05-03' AND my_table.boolean_column = 1;\n```\n\n### More Complex Queries\n\nAdvanced joins, where conditions, and aggregate methods are also supported.\n\n```\n$hcdb-\u003eselect(\n    'locations',\n    [\n        'locations' =\u003e ['PkID', 'Name', 'Address', 'Address2', 'City', 'State', 'Country','Zip', 'Lat', 'Lon', 'URL', 'Phone'],\n        'events' =\u003e ['LocID[count]', 'StartDate[min]']\n    ],\n    [\n        'AND' =\u003e [\n            'locations' =\u003e [\n                'Lon[!null]' =\u003e null,\n                'Lat[!=]' =\u003e '',\n                'Lon[!=]' =\u003e '',\n                'IsActive[=]' =\u003e '1',\n            ],\n            'events' =\u003e [\n                'LocID[\u003e]' =\u003e '0',\n                'IsActive[=]' =\u003e '1',\n                'IsApproved[=]' =\u003e '1',\n                'PkID[!null]' =\u003e null,\n                'StartDate[\u003e=]' =\u003e '2014-01-01',\n            ]\n        ],\n        'GROUP' =\u003e [\n            'locations' =\u003e ['PkID']\n        ],\n        'HAVING' =\u003e [\n            'CountLocID[\u003e]' =\u003e '0'\n        ],\n        'ORDER' =\u003e [\n            'locations.Name'\n        ]\n    ],\n    [\n        '[\u003e]events' =\u003e ['PkID', 'LocID']\n    ]\n);\n```\n\nResulting query\n\n```\nSELECT hc_locations.PkID, hc_locations.Name, hc_locations.Address, hc_locations.Address2, hc_locations.City, hc_locations.State, hc_locations.Country, hc_locations.Zip, hc_locations.Lat, hc_locations.Lon, hc_locations.URL, hc_locations.Phone, COUNT(hc_events.LocID), MIN(hc_events.StartDate) \nFROM hc_locations \n\tLEFT JOIN hc_events ON (hc_locations.PkID = hc_events.LocID) \nWHERE hc_locations.Lon IS NOT NULL\n\tAND  hc_locations.Lat != ''  \n\tAND  hc_locations.Lon != ''  \n\tAND  hc_locations.IsActive = 1  \n\tAND  hc_events.LocID \u003e 0  \n\tAND  hc_events.IsActive = 1  \n\tAND  hc_events.IsApproved = 1  \n\tAND  hc_events.PkID IS NOT NULL  \n\tAND  hc_events.StartDate \u003e= 2014-01-01  \nGROUP BY hc_locations.PkID\nHAVING COUNT(hc_events.LocID) \u003e 0\nORDER BY hc_locations.Name\n```\n\n### Additional Examples\ncl_database class will shortly be used in [Helios Calendar](https://github.com/chrislarrycarl/Helios-Calendar), which can be referenced for a variety of use case examples.\n\n\n## Credits\n\nThanks to [Medoo](http://medoo.in/doc) for the syntax inspiration which I have mimicked (nearly identically).\n\n\n## License\ncl_session is made available under the [LGPL](http://www.gnu.org/licenses/lgpl-2.1.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasdfdotdev%2Fcl_database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasdfdotdev%2Fcl_database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasdfdotdev%2Fcl_database/lists"}