{"id":24973363,"url":"https://github.com/pardnchiu/php-sql","last_synced_at":"2025-04-18T15:03:17.394Z","repository":{"id":275483904,"uuid":"926212964","full_name":"pardnchiu/PHP-SQL","owner":"pardnchiu","description":"PD\\SQL is a PDO-based SQL query builder that provides an elegant and secure way to construct and execute database queries in PHP.","archived":false,"fork":false,"pushed_at":"2025-02-03T12:33:04.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-03T16:51:31.281Z","etag":null,"topics":["mariadb","mysql","pardnchiu","pardnio","pardnltd","pdo","php-composer","php-library"],"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/pardnchiu.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":"2025-02-02T20:12:35.000Z","updated_at":"2025-02-03T12:33:08.000Z","dependencies_parsed_at":"2025-02-09T00:15:14.736Z","dependency_job_id":null,"html_url":"https://github.com/pardnchiu/PHP-SQL","commit_stats":null,"previous_names":["pardnchiu/phpsql"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnchiu%2FPHP-SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnchiu%2FPHP-SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnchiu%2FPHP-SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnchiu%2FPHP-SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pardnchiu","download_url":"https://codeload.github.com/pardnchiu/PHP-SQL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246148430,"owners_count":20731154,"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":["mariadb","mysql","pardnchiu","pardnio","pardnltd","pdo","php-composer","php-library"],"created_at":"2025-02-03T18:58:40.099Z","updated_at":"2025-03-29T06:27:31.928Z","avatar_url":"https://github.com/pardnchiu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PD\\SQL\n\n\u003e PD\\SQL is a PDO-based SQL query builder that provides an elegant and secure way to construct and execute database queries in PHP.\n\n![tag](https://img.shields.io/badge/tag-PHP%20Library-bb4444) \n![size](https://img.shields.io/github/size/pardnchiu/PHP-SQL/src/SQL.php)\u003cbr\u003e\n![version](https://img.shields.io/packagist/v/pardnchiu/sql)\n![download](https://img.shields.io/packagist/dm/pardnchiu/sql)\n\n## Features\n- Fluent interface for building SQL queries\n- Safe parameter binding to prevent SQL injection\n- Support for complex JOIN operations (INNER, LEFT, RIGHT)\n- Dynamic WHERE clause construction\n- Ordering and pagination support\n- Transaction handling\n- Query execution time monitoring\n- Environment-based configuration\n- Automatic connection management\n\n## functions\n\n- Table selection with `table()`\n- Custom field selection with `select()`\n- Conditional filtering with `where()`\n- Join operations with `join()`, `left_join()`, `right_join()`\n- Result ordering with `order_by()`\n- Pagination with `limit()` and `offset()`\n- Record creation with `insertGetId()`\n- Record updates with `update()`\n- Total row count with `total()`\n- Raw query execution with `query()` for complex custom queries\n\n## How to Use\n\n### Install\n\n```shell\ncomposer require pardnchiu/sql\n```\n\n```php\n\u003c?php\n\nuse PD\\SQL;\n\n$result_user_0 = SQL::table('users')\n   -\u003ewhere(\"status\", \"active\")\n   -\u003ewhere(\"age\", \"\u003e\", 18)\n   -\u003eget();\n\n$result_order = SQL::table(\"orders\")\n   -\u003eselect(\"orders.*\", \"users.name\")\n   -\u003ejoin(\"users\", \"orders.user_id\", \"users.id\")\n   -\u003ewhere(\"orders.status\", \"pending\")\n   -\u003eget();\n\n$result_product = SQL::table(\"products\")\n   -\u003etotal()\n   -\u003elimit(10)\n   -\u003eoffset(0)\n   -\u003eorder_by(\"created_at\", \"DESC\")\n   -\u003eget();\n\n$result_user_1 = SQL::query(\n    \"SELECT * FROM users WHERE status = ? AND role = ?\",\n    [\"active\", \"admin\"]\n);\n\ntry {\n    $result = SQL::table(\"users\")\n        -\u003ewhere(\"id\", 1)\n        -\u003eupdate([\n            \"status\" =\u003e \"active\",\n            \"updated_at\" =\u003e \"NOW()\"\n        ]);\n\n    if (!empty($result[\"info\"])) {\n        echo \"Performance: \" . $result[\"info\"];\n    };\n} catch (\\PDOException $e) {\n    echo \"Database Error: \" . $e-\u003egetMessage();\n} catch (\\Exception $e) {\n    echo \"General Error: \" . $e-\u003egetMessage();\n};\n```\n\n## License\n\nThis source code project is licensed under the [MIT](https://github.com/pardnchiu/PHP-SQL/blob/main/LICENSE) license.\n\n## Creator\n\n\u003cimg src=\"https://avatars.githubusercontent.com/u/25631760\" align=\"left\" width=\"96\" height=\"96\" style=\"margin-right: 0.5rem;\"\u003e\n\n\u003ch4 style=\"padding-top: 0\"\u003e邱敬幃 Pardn Chiu\u003c/h4\u003e\n\n\u003ca href=\"mailto:dev@pardn.io\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://pardn.io/image/email.svg\" width=\"48\" height=\"48\"\u003e\n\u003c/a\u003e \u003ca href=\"https://linkedin.com/in/pardnchiu\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://pardn.io/image/linkedin.svg\" width=\"48\" height=\"48\"\u003e\n\u003c/a\u003e\n\n***\n\n©️ 2024 [邱敬幃 Pardn Chiu](https://pardn.io)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpardnchiu%2Fphp-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpardnchiu%2Fphp-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpardnchiu%2Fphp-sql/lists"}