{"id":21056028,"url":"https://github.com/xp-framework/rdbms","last_synced_at":"2025-08-19T09:12:05.852Z","repository":{"id":11755277,"uuid":"14287411","full_name":"xp-framework/rdbms","owner":"xp-framework","description":"RDBMS support for the XP Framework: MySQL, Sybase, MSSQL, PostgreSQL, SQLite3, Interbase","archived":false,"fork":false,"pushed_at":"2024-10-05T13:40:59.000Z","size":4372,"stargazers_count":2,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-23T06:19:16.371Z","etag":null,"topics":["mssql","mysql","php","postgresql","rdbms","sqlite3","sybase","tds","transaction","xp-framework"],"latest_commit_sha":null,"homepage":null,"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/xp-framework.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"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":"2013-11-11T00:10:17.000Z","updated_at":"2024-10-05T13:41:04.000Z","dependencies_parsed_at":"2024-03-01T21:31:02.349Z","dependency_job_id":"3600cade-8bf2-4a0a-8133-88aaece61d93","html_url":"https://github.com/xp-framework/rdbms","commit_stats":null,"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"purl":"pkg:github/xp-framework/rdbms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Frdbms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Frdbms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Frdbms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Frdbms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-framework","download_url":"https://codeload.github.com/xp-framework/rdbms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Frdbms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261604610,"owners_count":23183675,"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":["mssql","mysql","php","postgresql","rdbms","sqlite3","sybase","tds","transaction","xp-framework"],"created_at":"2024-11-19T16:48:22.002Z","updated_at":"2025-07-11T16:15:54.719Z","avatar_url":"https://github.com/xp-framework.png","language":"PHP","readme":"RDBMS support for the XP Framework\n========================================================================\n\n[![Build status on GitHub](https://github.com/xp-framework/rdbms/workflows/Tests/badge.svg)](https://github.com/xp-framework/rdbms/actions)\n[![Build status on AppVeyor](https://ci.appveyor.com/api/projects/status/wyt2cgdnkvahlaqa?svg=true)](https://ci.appveyor.com/project/thekid/rdbms)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_0plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-framework/rdbms/version.svg)](https://packagist.org/packages/xp-framework/rdbms)\n\nRDBMS access APIs, connection manager, reverse engineering, O/R mapping.\n\nThe DriverManager model\n-----------------------\nTo retrieve a connection class from the driver manager, you need to use the rdbms.DriverManager class.\n\n```php\nuse rdbms\\DriverManager;\n\n$conn= DriverManager::getConnection('sybase://user:pass@server/NICOTINE');\n```\n\nThe DriverManager class expects a unified connection string (we call it DSN).\n\nSupported drivers\n-----------------\nThe DriverManager will select an appropriate driver from the DSN string via its name. This will load an implemenation class which is either based on a PHP extension or implements the protocol to communicate with the database system in userland code. For the latter case, you need not do anything to your PHP setup; if there's a hard dependency on a PHP extension, you need to install that before you can use the driver.\n\n| *Database system*  | *DSN name* | *PHP Extensions*        | *Userland driver*  |\n| ------------------ | ---------- | ----------------------- | ------------------ |\n| MySQL              | `mysql`    | ext/mysql or ext/mysqli | :white_check_mark: |\n| PostgreSQL         | `pgsql`    | ext/pgsql               |                    |\n| SQLite3            | `sqlite`   | ext/sqlite3             |                    |\n| Interbase/FireBird | `ibase`    | ext/interbase           |                    |\n| Sybase             | `sybase`   | ext/sybase-ct           | :white_check_mark: |\n| MSSQL              | `mssql`    | ext/mssql or ext/sqlsrv | :white_check_mark: |\n\nBasics\n------\nOnce we have fetched a specific database connection class, we can now invoke a number of methods on it.\n\n### Selecting\nSelecting can be done with the \"one-stop\" method `select()` which will return all results into an array. Alternatively, the `query()` method allows iterative fetching.\n\n```php\n$news= $conn-\u003eselect('news_id, caption, author_id from news');\n// $news= [\n//   [\n//     'news_id'   =\u003e 12,\n//     'caption'   =\u003e 'Hello World',\n//     'author_id' =\u003e 1549\n//   ]\n// ]\n\n$q= $conn-\u003equery('select news_id, caption, author_id from news');\nwhile ($record= $q-\u003enext()) {\n  // $record= [\n  //   'news_id'   =\u003e 12,\n  //   'caption'   =\u003e 'Hello World',\n  //   'author_id' =\u003e 1549\n  // ]\n}\n```\n\n### Inserting\nTo \"bind\" parameters to an SQL query, the query, select, update, delete and insert methods offer a printf style tokenizer and support varargs syntax. These take care of NULL, type handling and proper escaping for you.\n\n```php\n$conn-\u003einsert('\n  into news (\n    caption, author_id, body, extended, created_at\n  ) values (\n    %s, -- caption\n    %d, -- author_id\n    %s, -- body\n    %s, -- extended\n    %s  -- created_at\n  )',\n  $caption,\n  $authorId,\n  $body,\n  $extended,\n  Date::now()\n);\n```\n\n### Updating\nThe `update()` and `delete()` methods will return the number of affected rows, in case you're interested.\n\n```php\n$conn-\u003eupdate('news set author_id= %d where author_id is null', $authorId);\n```\n\n### Deleting\nEven if your RDBMS requires you to use single quotes (or what-else), the API will take care of rewriting string literals for you.\n\n```php\n$conn-\u003edelete('from news where caption = \"[DELETE]\"');\n```\n\nExceptions\n----------\nAll of the above methods will throw exceptions for failed SQL queries, syntax errors, connection failure etc. All these exceptions are subclasses of `rdbms.SQLException`, so to catch all possible errors, use it in the catch clause:\n\n\n```\n+ rdbms.SQLException\n|-- rdbms.ConnectionNotRegisteredException\n|-- rdbms.SQLConnectException\n|-- rdbms.SQLStateException\n`-- rdbms.SQLStatementFailedException\n    |-- rdbms.SQLConnectionClosedException\n    `-- rdbms.SQLDeadlockException\n```\n\nTransactions\n------------\nTo start a transaction, you can use the connection's `begin()`, `commit()` and `rollback()` methods as follows:\n\n```php\npublic function createAuthor(...) {\n  $tran= $conn-\u003ebegin(new Transaction('create_author'));\n\n  try {\n    $id= $conn-\u003einsert('into author ...');\n    $conn-\u003einsert('into notify ...');\n\n    $tran-\u003ecommit();\n    return $id;\n  } catch (SQLException $e) {\n    $tran-\u003erollback();\n    throw $e;\n  }\n}\n```\n\n*Note: Not all database systems support transactions, and of those that do, not all support nested transactions. Be sure to read the manual pages of the RDBMS you are accessing.*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Frdbms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-framework%2Frdbms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Frdbms/lists"}