{"id":15178949,"url":"https://github.com/ezrarieben/pdo-wrapper-singleton","last_synced_at":"2026-03-01T01:34:42.025Z","repository":{"id":222015394,"uuid":"755950729","full_name":"ezrarieben/pdo-wrapper-singleton","owner":"ezrarieben","description":"A wrapper class for PDO MySQL DB connections following the singleton pattern.","archived":false,"fork":false,"pushed_at":"2024-02-11T23:04:48.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-17T01:04:42.896Z","etag":null,"topics":["database","databases","mysql","mysql-database","pdo","pdo-mysql","pdo-wrapper","php","wrapper","wrapper-class"],"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/ezrarieben.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":"2024-02-11T15:06:10.000Z","updated_at":"2024-02-11T22:01:02.000Z","dependencies_parsed_at":"2024-02-11T20:19:46.807Z","dependency_job_id":"41eefce3-3792-4efe-a0af-24315e355393","html_url":"https://github.com/ezrarieben/pdo-wrapper-singleton","commit_stats":{"total_commits":5,"total_committers":2,"mean_commits":2.5,"dds":"0.19999999999999996","last_synced_commit":"36284102cc99a2ed55cf392ffdebe74b63d793ef"},"previous_names":["ezrarieben/pdo-wrapper-singleton"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ezrarieben/pdo-wrapper-singleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezrarieben%2Fpdo-wrapper-singleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezrarieben%2Fpdo-wrapper-singleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezrarieben%2Fpdo-wrapper-singleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezrarieben%2Fpdo-wrapper-singleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezrarieben","download_url":"https://codeload.github.com/ezrarieben/pdo-wrapper-singleton/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezrarieben%2Fpdo-wrapper-singleton/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29957397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T22:53:01.873Z","status":"ssl_error","status_checked_at":"2026-02-28T22:52:50.699Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["database","databases","mysql","mysql-database","pdo","pdo-mysql","pdo-wrapper","php","wrapper","wrapper-class"],"created_at":"2024-09-27T15:42:42.052Z","updated_at":"2026-03-01T01:34:41.967Z","avatar_url":"https://github.com/ezrarieben.png","language":"PHP","readme":"# pdo-wrapper-singleton\n\nA wrapper class written in PHP for PDO MySQL DB connections following the singleton pattern.\u003cbr /\u003e\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n# Table of contents\n\n- [pdo-wrapper-singleton](#pdo-wrapper-singleton)\n- [Table of contents](#table-of-contents)\n- [Installation](#installation)\n- [Basic example](#basic-example)\n- [Usage](#usage)\n  - [Importing wrapper class](#importing-wrapper-class)\n  - [Setting up DB connection](#setting-up-db-connection)\n      - [Minimal setup example](#minimal-setup-example)\n      - [Extensive setup example](#extensive-setup-example)\n      - [Available parameters](#available-parameters)\n  - [DB interaction](#db-interaction)\n    - [Using PDO functions](#using-pdo-functions)\n    - [Prepared statements](#prepared-statements)\n      - [Example](#example)\n      - [Example with named parameters](#example-with-named-parameters)\n  - [Error handling](#error-handling)\n\n# Installation\n\nTo use the wrapper in your project, add it as a dependency via composer:\n\n```\ncomposer require ezrarieben/pdo-wrapper-singleton\n```\n\n# Basic example\n\n```php\nuse \\ezrarieben\\PdoWrapperSingleton\\Database;\n\nDatabase::setHost(\"localhost\");\nDatabase::setUser(\"user\");\nDatabase::setPassword(\"123456\");\nDatabase::setDbName(\"foobar\");\n\ntry {\n    $query = \"SELECT * FROM `cars` WHERE `color` = ?\";\n    $stmt = Database::run($query, ['red']);\n    $row = $stmt-\u003efetch();\n} catch (\\PDOException $e) {\n    die(\"PDO ERROR: \" . $e-\u003egetMessage());\n}\n```\n\n# Usage\n\n## Importing wrapper class\n\nFor ease of use it is recommended to import the wrapper class with `use`\n\n```php\nuse \\ezrarieben\\PdoWrapperSingleton\\Database;\n```\n\n## Setting up DB connection\n\nIn order to use the wrapper class `Database` the connection parameters need to be set first.\n\nThere are certain required parameters that need to be set in order for the PDO connection to work.\n\u003cbr/\u003e(See \"Required\" column in [available parameters table](#available-parameters) for required parameters).\n\n#### Minimal setup example\n\n```php\nDatabase::setHost(\"localhost\");\nDatabase::setUser(\"user\");\nDatabase::setPassword(\"123456\");\n```\n\n#### Extensive setup example\n\n```php\nDatabase::setHost(\"localhost\");\nDatabase::setPort(3307);\nDatabase::setUser(\"user\");\nDatabase::setPassword(\"123456\");\nDatabase::setDbName(\"foobar\");\nDatabase::setPdoAttributes(array(\n    PDO::ATTR_DEFAULT_FETCH_MODE =\u003e PDO::FETCH_OBJ,\n));\n```\n\n#### Available parameters\n\n| Description    | Setter function      | Parameters          | Required |\n| -------------- | -------------------- | ------------------- | -------- |\n| DB server host | `setHost()`          | `string` $host      | **YES**  |\n| User           | `setUser()`          | `string` $user      | **YES**  |\n| Password       | `setPassword()`      | `string` $password  | **YES**  |\n| DB server host | `setPort()`          | `int` $port         |          |\n| Database name  | `setDbName()`        | `?string` $dbName   |          |\n| PDO attributes | `setPdoAttributes()` | `array` $attributes |          |\n\n## DB interaction\n\n### Using PDO functions\n\nAll PDO functions can be accessed statically through the `Database` class:\n\n```php\n$query = \"SELECT * FROM `cars` WHERE `color` = ?\";\n$stmt = Database::prepare($query);\n$stmt-\u003eexecute(['red']);\n$row = $stmt-\u003efetch();\n```\n\n### Prepared statements\n\nThe `Database` class has a shortcut function for prepared statements called `run()`:\n\n| Parameters      | Description                 | Required |\n| --------------- | --------------------------- | -------- |\n| `string` $query | SQL query to execute        | **YES**  |\n| `array` $params | parameters to pass to query |          |\n\nThe function returns a `PDOStatement` object if preperation and execution of query was successfull.\n\u003cbr/\u003eIf preperation or execution of query failed the function will throw a `PDOException` or return `false` depending on the currently set PDO error mode.\n\u003cbr/\u003e(see: [Error handling](#error-handling) for more info)\n\n#### Example\n\n```php\n$query = \"SELECT * FROM `cars` WHERE `color` = ?\";\n$stmt = Database::run($query, ['red']);\n$row = $stmt-\u003efetch();\n```\n\n#### Example with named parameters\n\n```php\n$query = \"SELECT * FROM `cars` WHERE `color` = :color\";\n$stmt = Database::run($query, [':color' =\u003e 'red']);\n$row = $stmt-\u003efetch();\n```\n\n## Error handling\n\nPDO's [error mode](https://www.php.net/manual/en/pdo.error-handling.php) is set to `ERRMODE_EXCEPTION` by default.\n\u003cbr/\u003eError handling can therefore be done through try and catch blocks.\n\n```php\ntry {\n    $query = \"SELECT * FROM `cars` WHERE `color` = ?\";\n    $stmt = Database::run($query, ['red']);\n    $row = $stmt-\u003efetch();\n} catch (PDOException $e) {\n    // Handle exception\n}\n```\n\nWhen switching to a different [error mode](https://www.php.net/manual/en/pdo.error-handling.php) you will need to handle errors through booleans.\n\n\u003e **NOTE:** Error handling using booleans is only supported if you change PDO's error mode.\n\n```php\n$query = \"SELECT * FROM `cars` WHERE `color` = :color\";\nif($stmt = Database::run($query, [':color' =\u003e 'red'])) {\n    // Preparing and executing statement was successfull so fetch the result\n    $row = $stmt-\u003efetch();\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezrarieben%2Fpdo-wrapper-singleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezrarieben%2Fpdo-wrapper-singleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezrarieben%2Fpdo-wrapper-singleton/lists"}