{"id":37754500,"url":"https://github.com/offworks/overnight","last_synced_at":"2026-01-16T14:27:05.454Z","repository":{"id":57030396,"uuid":"60008492","full_name":"offworks/overnight","owner":"offworks","description":"A simple php-mysql query builder based on pdo","archived":false,"fork":false,"pushed_at":"2019-06-24T11:06:07.000Z","size":32,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-02T04:42:14.400Z","etag":null,"topics":["builder","dbal","mysql","pdo","php","query"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/offworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-30T12:28:45.000Z","updated_at":"2023-01-03T05:45:45.000Z","dependencies_parsed_at":"2022-08-23T17:41:04.487Z","dependency_job_id":null,"html_url":"https://github.com/offworks/overnight","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/offworks/overnight","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offworks%2Fovernight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offworks%2Fovernight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offworks%2Fovernight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offworks%2Fovernight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/offworks","download_url":"https://codeload.github.com/offworks/overnight/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offworks%2Fovernight/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["builder","dbal","mysql","pdo","php","query"],"created_at":"2026-01-16T14:27:04.934Z","updated_at":"2026-01-16T14:27:05.448Z","avatar_url":"https://github.com/offworks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overnight\nAn overnightly simple and consistent PHP-mysql query builder based on PDO.\n\n## Installation\n##### Composer\n```\ncomposer require offworks/overnight\n```\n##### Git clone\n```\ngit clone https://github.com/offworks/overnight\n```\nthen, require the autoload from the location\n```\nrequire_once __DIR__.'/path/to/overnight/src/autoload.php';\n```\n\n## Usage\n#### Create connection\n```\n$db = \\Overnight\\Connection::create('localhost', 'user', 'password', 'dbname');\n```\n\n### SELECT\n##### WHERE\nGet an array of records\n```\n$users = $db-\u003etable('user')\n        -\u003ewhere('created_at \u003e ?', array(date('Y-m-d H:i:s'))\n        -\u003eexecute()-\u003eall();\n```\nGet an associated key value single (first) record\n```\n$user = $db-\u003efrom('user')\n        -\u003eselect('name, email, birthdate')\n        -\u003ewhere('user_id = ?', array($userId))\n        -\u003eexecute()-\u003efirst();\n```\n*p/s : from() is an alias of table()*\n\nMultiple wheres\n```\n$tickets = $db-\u003efrom('ticket')\n           -\u003ewhere('available = ? AND used = ?', array(1, 0))\n           -\u003ewhere('expiry_date \u003c ?', array('2020-10-10'))\n           -\u003eandWhere('seat_type = ?', array('single'))\n           -\u003eorWhere('master_ticket = ?', array(1))\n           -\u003eexecute();\n\n// will execute something like\nSELECT * FROM ticket WHERE available = 1 AND used = 0 AND expiry_date \u003c '2020-10-10' AND seat_type = 'single'\n```\n\n##### INNER JOIN\n```\n$books = $db-\u003efrom('book')\n         -\u003einnerJoin('author ON author.author_id = book.author_id')\n         -\u003eexecute()-\u003eall();\n```\n##### LEFT JOIN\n```\n$users = $db-\u003efrom('user')\n         -\u003eleftJoin('membership ON membership.user_id = user.user_id')\n         -\u003eexecute()-\u003eall();\n```\nParameterized join\n```\n$users = $db-\u003efrom('book')\n        -\u003einnerJoin('author ON author.author_id = book.author_id AND author.is_alive = ?', array(1))\n        -\u003eexecute()-\u003eall();\n```\n\n##### ORDER BY\n```\n$students = $db-\u003efrom('student')\n            -\u003ewhere('is_alive = ?', array(1))\n            -\u003eorderBy('last_seen DESC')\n            -\u003eexecute()-\u003eall();\n```\n\n##### GET RAW SQL\n```\n$sql = $db-\u003efrom('news')\n       -\u003einnerJoin('editor ON news.editor_id = editor.editor_id')\n       -\u003ewhere('DATE(published_at) = ?', array(date('Y-m-d H:i:s')))\n       -\u003eorderBy('published_at DESC')\n       -\u003egetSql();\n```\n\n### INSERT\n```\n$db-\u003einsert('user')-\u003evalues(array(\n    'name' =\u003e 'James',\n    'like' =\u003e 'Foo cake',\n    'birthdate' =\u003e '1977-05-09'\n  ))-\u003eexecute();\n```\nor\n```\n$db-\u003einsert('user', array(\n    'name' =\u003e 'James',\n    'like' =\u003e 'Foo cake',\n    'birthdate' =\u003e '1977-05-09'\n  ))-\u003eexecute();\n```\n\n#### Last insert id\n```\n$userId = $db-\u003elastInsertId();\n```\nor\n```\n$userId = $db-\u003einsert('user')-\u003evalues($values)-\u003eexecute()-\u003eid();\n```\n\n### UPDATE\n```\n$db-\u003eupdate('book')\n-\u003ewhere('book_id = ?', array($bookId))\n-\u003eset(array('title' =\u003e 'the lost marble - first edition'))\n-\u003eexecute();\n```\n\n### DELETE\n```\n$db-\u003edelete('author')\n-\u003ewhere('author_id = ?', array($authorId))\n-\u003eexecute();\n```\n\n## APIs\n#### General\n```\n$query-\u003eexecute()\n  getStatement()\n$query-\u003egetSql()\n$db-\u003elastInsertId()\n$db-\u003eexecute(string $sql, array $values, array $params))\n$db-\u003egetPdo()\n```\n\n#### Select\n```\nfrom(string $table) or table(string $table)\nselect(string|array $columns)\nwhere(string $condition, array $values = array())\norWhere(string $condition, array $values = array())\norderBy(string $orderBy)\ngroupBy(string $groupBy)\ninnerJoin(string $condition, array $values = array())\nleftJoin(string $condition, array $values = array())\nrightJoin(string $condition, array $values = array())\nlimit(int $limit, int $offset = null)\nhaving(string $condition, array $values = array())\nexecute()-\u003eall()\nexecute()-\u003efirst()\n```\n\n#### Insert\n```\ninsert(string $table, array $values = array())\nvalues(array $values)\nexecute()-\u003eid()\n```\n\n#### Update\n```\nupdate(string $table)\nset(array $data)\nwhere(string $condition, array $values = array())\norWhere(string $condition, array $values = array())\n```\n#### Delete\n```\ndelete(string $table)\nwhere(string $condition, array $values = array())\norWhere(string $condition, array $values = array())\n```\n\n## License\n[MIT](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffworks%2Fovernight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foffworks%2Fovernight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffworks%2Fovernight/lists"}