{"id":21700694,"url":"https://github.com/marcocesarato/database-web-api","last_synced_at":"2025-09-09T18:22:08.899Z","repository":{"id":54559922,"uuid":"133151614","full_name":"marcocesarato/Database-Web-API","owner":"marcocesarato","description":"Dynamically generate RESTful APIs from the contents of a database table. Provides JSON, XML, and HTML. Supports most popular databases","archived":false,"fork":false,"pushed_at":"2024-11-06T18:54:52.000Z","size":1355,"stargazers_count":50,"open_issues_count":6,"forks_count":25,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T12:11:13.211Z","etag":null,"topics":["apc","api","auth","authentication","database","database-api","database-management","dataset","html","html5","json","mysql","php","postgres","query","rest","rest-api","restful-api","web","xml"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcocesarato.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":"2018-05-12T14:03:16.000Z","updated_at":"2025-02-20T10:47:00.000Z","dependencies_parsed_at":"2025-02-24T02:10:39.025Z","dependency_job_id":"724109bd-dc49-48ce-a38f-2a1914d76684","html_url":"https://github.com/marcocesarato/Database-Web-API","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FDatabase-Web-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FDatabase-Web-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FDatabase-Web-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FDatabase-Web-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcocesarato","download_url":"https://codeload.github.com/marcocesarato/Database-Web-API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054195,"owners_count":21039952,"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":["apc","api","auth","authentication","database","database-api","database-management","dataset","html","html5","json","mysql","php","postgres","query","rest","rest-api","restful-api","web","xml"],"created_at":"2024-11-25T20:16:22.300Z","updated_at":"2025-04-09T14:11:35.733Z","avatar_url":"https://github.com/marcocesarato.png","language":"PHP","readme":"# PHP Database Web API\n![](cover.png)\n\n**Version:** 0.7.0\n\n**Github:** https://github.com/marcocesarato/Database-Web-API\n\n**Author:** Marco Cesarato\n\n## Description\nDynamically generate RESTful APIs from the contents of a database table. Provides JSON, XML, and HTML. Supports most popular databases.\n\n## What problem this solves\nCreating an API to access information within existing database tables is laborious task, when done as a bespoke task. This is often dealt with by exporting the contents of the database as CSV files, and providing downloads of them as a “good enough” solution.\n\n## How this solves it\nDatabase Web API acts as a filter, sitting between a database and the browser, allowing users to interact with that database as if it was a native API. The column names function as the key names. This obviates the need for custom code for each database layer.\n\nWhen Alternative PHP Cache (APC) is installed, parsed data is stored within APC, which accelerates its functionality substantially. While APC is not required, it is recommended highly.\n\n## Wiki\n\nGo to this link for go to the wiki of the platform and have a better informations about the usage of this platform and have more examples:\n \n https://github.com/marcocesarato/Database-Web-API/wiki\n\n## Databases supported\n* 4D\n* CUBRID\n* Firebird/Interbase\n* IBM\n* Informix\n* MS SQL Server\n* MySQL\n* ODBC and DB2\n* Oracle\n* PostgreSQL\n* SQLite\n\n### Requirements\n* PHP\n* Database\n* APC (optional)\n\n## Installation\n* Set the configuration on `config.php`. Follow the below example to register a new dataset. Tip: It's best to provide read-only database credentials here if you want read only.\n* _(Optional)_ If you want enable an authentication system you must compile on the `config.php` the constant `__API_AUTH__` as on the example below.\n* _(Optional)_ Document the API. For this you can use auto-documentation using file `docs.php`\n* _(Optional)_ Use Hooks for manage permissions (as `can_read`, `can_write`, `can_edit`, `can_delete`)\n\n## Configuration\nEdit `config.php` to include a single instance of the following for each dataset (including as many instances as you have datasets):\n\n### Define API Name\n```php\ndefine(\"__API_NAME__\", \"Database Web API\"); // API Name\n```\n\n### Define datasets\n\n**Dataset configurations:**\n\n| Settings         | Description                                                                        | Default   |\n|------------------|------------------------------------------------------------------------------------|-----------|\n| default          | Default dataset                                                                    | false     |\n| api              | Accessible through API                                                             | true      |\n| name             | Database Name                                                                      |           |\n| username         | Database Username                                                                  | root      |\n| password         | Database Password                                                                  | root      |\n| server           | Database Server Address                                                            | localhost |\n| ttl              | Cache time to live (set 1 for disable)                                             | 3600      |\n| port             | Database Port                                                                      | 3306      |\n| type             | Database Type (ex. `mysql`, `psql` ecc..)                                          | mysql     |\n| table_list       | Database Tables Whitelist (Allow only the tables in this list, if empty allow all) | null      |\n| table_blacklist  | Database Tables Blacklist                                                          | null      |\n| table_docs       | Database Documentation (ex. /dataset/docs/table.html)                             | array()   |\n| column_list      | Database Columns's whitelist (Allow only the columns in this list, if empty allow all)      | null      |\n| column_blacklist | Database Columns's blacklist                                                                | null      |\n\n#### Example complete with explanation\n```php\ndefine(\"__API_DATASETS__\", serialize(array(\n\t'dataset' =\u003e array(\n\t\t'default' =\u003e true, // Default dataset\n\t\t'api' =\u003e true, // Accessible from API request url (ex. is false if you have a different database for auth users)\n\t\t'name' =\u003e 'database_name', // Database name\n\t\t'username' =\u003e 'user', // root is default\n\t\t'password' =\u003e 'passwd', // root is default\n\t\t'ttl' =\u003e 1, // Cache time to live. Disable cache (1 second only)\n\t\t'server' =\u003e 'localhost',  // localhost default\n\t\t'port' =\u003e 5432, // 3306 is default\n\t\t'type' =\u003e 'pgsql', // mysql is default\n\t\t'table_list' =\u003e array( // Tables's whitelist (Allow only the tables in this list, if empty allow all)\n\t\t\t'users'\n\t\t),\n\t\t'table_blacklist' =\u003e array( // Tables's blacklist\n\t\t\t'passwords'\n\t\t),\n\t\t'table_docs' =\u003e array(\n\t\t\t/** @example\n\t\t\t'table' =\u003e array(\n\t\t\t\t\"column\" =\u003e array(\n\t\t\t\t\"description\" =\u003e \"Column description\",\n\t\t\t\t\t\"example\" =\u003e \"1\",\n\t\t\t\t),\n\t\t\t),\n\t\t\t*/\n\t\t), // For Autodocoumentation, url ex. /dataset/docs/table.html\n\t\t'column_list' =\u003e array( // Columns's whitelist (Allow only the columns in this list, if empty allow all)\n\t\t\t'users' =\u003e array(\n\t\t\t\t'username',\n\t\t\t\t'name',\n\t\t\t\t'surname'\n\t\t\t)\n\t\t),\n\t\t'column_blacklist' =\u003e array( // Columns's blacklist\n\t\t\t'users' =\u003e array(\n\t\t\t\t'password',\n\t\t\t)\n\t\t),\n\t),\n)));\n```\n\n**Note:** All fields of `__API_DATASETS__` (except the name of database) are optional and will default to the above.\n\n#### Example \n\nHere is a dataset example for a MySQL database named “inspections,” accessed with a MySQL user named “website” and a password of “s3cr3tpa55w0rd,” with MySQL running on the same server as the website, with the standard port of 3306. All tables may be accessed by Database to API except for “cache” and “passwords,” and among the accessible tables, the “password_hint” column may not be accessed via Database to API. All of this is registered to create an API named “facility-inspections”.\n\n```php\narray( \n\t'default' =\u003e true,\n\t'name' =\u003e 'inspections',\n\t'username' =\u003e 'website',\n\t'password' =\u003e 's3cr3tpa55w0rd',\n\t'server' =\u003e 'localhost',\n\t'ttl' =\u003e 1,\n\t'port' =\u003e 3306,\n\t'type' =\u003e 'mysql',\n\t'table_docs' =\u003e array(),\n\t'table_list' =\u003e array(),\n\t'table_blacklist' =\u003e array('cache', 'passwords'),\n\t'column_blacklist' =\u003e array('password_hint'),\n\t'column_list' =\u003e array(),\n);\n```\n\nRetrieving the contents of the table history within this dataset as JSON would be accomplished with a request for /facility-inspections/history.json. Note that it is the name of the dataset (facility-inspections) and not the name of the database (inspections) that is specified in the URL.\n\nFor a SQLite database, simply provide the path to the database in name.\n\nFor an Oracle database, you can either specify a service defined in tsnames.ora (e.g. dept_spending) or you can define an Oracle Instant Client connection string (e.g., //localhost:1521/dept_spending).\n\n\n\n### _(Optional)_ Authentication system\n\n#### Auth configuration\n\n| Setting         | Description                                                       | Type  |\n|-----------------|-------------------------------------------------------------------|-------|\n| sqlite          | When enabled store token on SQLite file                          | Bool  |\n| sqlite_database | SQLite filename (only if sqlite = true)                           | Text  |\n| api_database    | Set database name where create api_table (Only if sqlite = false) (`__DATASET__`) | Text  |\n| api_table       | Set database table name where store tokens                        | Text  |\n| users           | Users table to validate                                           | Array |\n\n\n##### Users configuration\n\n| Setting  | Description                                                                                                                                                                                    | Type  |\n|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------|\n| database | Database where users are stored (`__DATASET__`)                                                                                                                                                                | Bool  |\n| table    | Users table name                                                                                                                                                                               | Text  |\n| columns  | 'id' =\u003e 'user_id' // Id column name\u003cbr\u003e'username' =\u003e 'user_name' // Username column name\u003cbr\u003e'password' =\u003e 'password' // Password column name\u003cbr\u003e'admin' =\u003e array('is_admin' =\u003e 1) // Admin condition (can be null) | Array |\n| search   | Search condition                                                                                                                                                                               | Text  |\n| check    | Validation users condition (ex. is_active = 1) (can be null)                                                                                                                                                 | Text |\n\n```php\ndefine(\"__API_AUTH__\",  serialize(array( // Set null for disable authentication\n\t'sqlite' =\u003e false, // Enabled save token on SQLite file\n\t'sqlite_database' =\u003e 'api_token', // SQLite filename (only with sqlite = true)\n\t'api_database' =\u003e 'dataset', // Authentication database\n\t'api_table' =\u003e 'api_authentications', // API token table name\n\t'users' =\u003e array(\n\t\t'database' =\u003e 'dataset', // Database where users are stored\n\t\t'table' =\u003e 'users', // Table where users are stored\n\t\t'columns' =\u003e array(\n\t\t\t'id' =\u003e 'user_id', // Id column name\n\t\t\t'username' =\u003e 'user_name', // Username column name\n\t\t\t'password' =\u003e 'password', // Password column name\n\t\t\t'admin' =\u003e array('is_admin' =\u003e 1) // Admin bypass condition. With this condition true API bypass all black/whitelists and permissions. Set NULL for disable\n\t\t),\n\t\t'search' =\u003e array('user_id', 'email', 'username'), // Search user by these fields\n\t\t'check' =\u003e array('active' =\u003e 1) // Some validation checks. In this case if the column 'active' with value '1'. Set NULL for disable\n\t),\n)));\n```\n\n## API Structure\n\n### Format availables:\n\n- JSON\n\n- XML\n\n- HTML\n\n\n### Generic URL format for all kind of request:\n\n#### Standard\n\n* Fetch all: `/[database]/[table].[format]`\n* Fetch all with limit: `/[database]/[limit]/[table].[format]`\n* Fetch: `/[database]/[table]/[ID].[format]`\n* Fetch search by column: `/[database]/[table]/[column]/[value].[format]`\n* Documentation: `/[database]/docs/[table].[format]`\n  \n\n## Authentication\n\nAuthentication needed for browse the database.\n\nThe authentication permit to managed the privilege of the users (read, write, modify, delete)\n\n- Authentication: `/auth.[format]`\n\nSet the header **Auth-Account** with the username/user id and **Auth-Password** with the encrypted password like this:\n\n**Request example:**\n\n```http\nGET /auth.json HTTP/1.1\nHost: localhost\nAuth-Account: marco.cesarato\nAuth-Password: md5password\n```\n\n**Response example:**\n\n```json\n[{\"token\": \"b279fb1d0708ed81e7a194e0c5d928b6\"}]\n```\n\n **Example of token usage on GET, POST, PUT, PATCH and DELETE requests:**\n\nSet the header **Access-Token** with the token values received from auth request like this:\n\n```http\nGET /database/users.json` HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n```\n\n\n## Check Authentication\n\nCheck authentication check is needed for verify if a token is valid.\n\n- Check authentication: `/auth/check.[format]`\n\n**Request example:**\n\n```http\nGET /auth/check.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n```\n\n**Response example:**\n\n```json\n{\n\n\t\"user\": {\n\t\t\"id\": \"1\",\n\t\t\"role_id\": \"\",\n\t\t\"is_admin\": true\n\t},\n\t\"response\": {\n\t\t\"status\": 200,\n\t\t\"message\": \"OK\"\n\t}\n\n}\n```\n\n\n## GET Request\n\nRetrieve data from dataset\n\n- Fetch all: `/[database]/[table].[format]`\n\n- Fetch all with limit: `/[database]/[limit]/[table].[format]`\n\n- Fetch: `/[database]/[table]/[ID].[format]`\n\n- Fetch search by column: `/[database]/[table]/[column]/[value].[format]`\n\n- Fetch all joining table:\n\n  ```js\n  join[table] = array(\n\t'on' =\u003e \u003ccolumn_id\u003e,\t\t   // Column of the table joined\n\t'value' =\u003e \u003cvalue\u003e,\t\t\t// Column of main table or value\n\t'method' =\u003e (left|inner|right) // Optional\n  )\n  ```\n\n  **Example with value:**\n\n  ```js\n  join[users]['on'] = id\n  join[users]['value'] = 1\n  join[users]['method'] = 'INNER'\n  ```\n\n  **Example with column:**\n\n  ```js\n  join[users]['on'] = id\t\t\t// Column of the table joined\n  join[users]['value'] = user_id\t// Column of the main table (no users)\n  join[users]['method'] = 'INNER'\n  ```\n\n- Additional parameters\n\nex: `/[database]/[table]/[column]/[value].[format]?order_by=[column]\u0026direction=[direction]`\n\n**Examples of GET requests:**\n\n```http\nGET /dataset/users.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n```\n\n```http\nGET /dataset/10/users.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n```\n\n```http\nGET /dataset/users/1.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n```\n\n```http\nGET /dataset/users/is_active/1.json?order_by=username\u0026direction=desc HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n```\n\n### Advanced search\n\n**Note:** These examples are valid only for **GET** and **PUT** requests\n\nSearch single value\n\n```php\nwhere[column]\t\t\t   = 1\t  // column = 1\nwhere[column][=]\t\t   = 1\t  // column = 1\nwhere[column][!]\t\t   = 1    // column != 1\nwhere[column][\u003e]\t\t   = 1\t  // column \u003e 1\nwhere[column][\u003c]\t\t   = 1\t  // column \u003c 1\nwhere[column][\u003e=]\t\t   = 1\t  // column \u003e= 1\nwhere[column][\u003c=]\t\t   = 1\t  // column \u003c= 1\nwhere[column][%]\t\t   = \"%1\" // column LIKE \"%1\"\n```\n\nSearch multiple values\n\n```php\nwhere[column]\t\t\t   = array(1,5,7)\t  // IN (...) (IN can be equal to an OR)\nwhere[column][=]\t\t   = array(1,5,7)\t  // IN (...) \nwhere[column][!]\t\t   = array(1,5,7)\t  // NOT IN (...)\nwhere[column][\u003e]\t\t   = array(1,2)\t      // column \u003e 1 OR column \u003e 2\nwhere[column][\u003c]\t\t   = array(1,2)\t      // column \u003c 1 OR column \u003c 2\nwhere[column][\u003e=]\t\t   = array(1,2)\t      // column \u003e= 1 OR column \u003e= 2\nwhere[column][\u003c=]\t\t   = array(1,2)\t      // column \u003c= 1 OR column \u003c= 2\nwhere[column][%]\t\t   = array(\"%1\",\"%2\") // column LIKE \"%1\" OR column LIKE \"%2\"\n```\n\nSpecify column's table\n\n```php\nwhere['table.column'][=] = array(1,5,7)\n```\n\nCompare between two different table columns\n\n```php\nwhere['table_a.column_a'] = 'table_b.column_b'\n```\n\nCompare between different columns of main table\n\n```php\nwhere['column_a'] = 'table_a.column_b'\n// OR\nwhere['table_a.column_a'] = 'table_a.column_b'\n\t\n// WRONG\nwhere['column_a'] = 'column_b'\n```\n\n### Additional parameters\n\n- `order_by`: column_name\n\n  Can be and array or a string\n\n  ```php\n  order_by = 'username, name, surname'\n  // OR\n  order_by = array('username', 'name', 'surname')\n  ```\n\n  for more specific order direction\n\n  ```php\n  order_by['users.username'] = 'DESC'\n  ```\n  \n  for cast a specific type\n  \n  ```php\n  order_by['users.username::varchar'] = 'DESC'\n  order_by['users.id::int'] = 'DESC'\n  ```\n\n- `direction`:  `ASC` or `DESC` (default `ASC`)\n\n- `limit`: max elements to retrieve\n\nex: `/[database]/[tabel]/[colomn]/[value].[format]?order_by=[column]\u0026direction=[direction]`\n\n### Documentation\n\n*PS:* Work only with pgsql and mysql database type at the moment\n\nFor get auto-documentation of a database table:\n\n- Documentation index URL format : `/[database]/docs/index.[format]`\n- Documentation URL format: `/[database]/docs/[table].[format]`\n\nFor have a separated file where document your database you can use `/docs.php`\n\n\n\n## POST Request\n\nInsert data\n\n**Single insert:**\n\n- Select the table on URL: `/[database]/[table].[format]`\n- Insert parameter: `insert[\u003ccolumn\u003e] = \u003cvalue\u003e`\n\n**Multiple insert:**\n\n- Select dataset on URL: `/[database].[format]`\n- Insert parameter: `insert[\u003ctable\u003e][\u003ccolumn\u003e] = \u003cvalue\u003e`\n\n**Note**: At the moment you can add only one row for table\n\n**Examples of POST requests:**\n\n**Single insert:**\n\n```http\nPOST /dataset/users.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n\ninsert[username]=Marco\u0026insert[email]=cesarato.developer@gmail.com\u0026insert[password]=3vwjehvdfjhefejjvw\u0026insert[is_active]=1\n```\n\n**Multiple insert:**\n\n```http\nPOST /dataset.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n\ninsert[users][username]=Marco\u0026insert[users][email]=cesarato.developer@gmail.com\u0026insert[users][password]=3vwjehvdfjhefejjvw\u0026insert[users][is_active]=1\n```\n\n```http\nPOST /dataset.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n\ninsert[users][0][username]=Marco\u0026insert[users][0][email]=cesarato.developer@gmail.com\u0026insert[users][0][password]=3vwjehvdfjhefejjvw\u0026insert[users][0][is_active]=1\u0026insert[users][1][username]=Brad\u0026insert[users][1][email]=brad@gmail.com\u0026insert[users][1][password]=erwerwerffweeqewrf\u0026insert[users][1][is_active]=1\n```\n\n## PATCH/PUT Request\n\nUpdate data\n\n**Single update:**\n\n- Select the row on URL: `/[database]/[table]/[id].[format]`\n- Update parameter: `update[\u003ccolumn\u003e] = \u003cvalue\u003e`\n\n**Multiple update:**\n\n- Select the dataset on URL: `/[database].[format]`\n- Update parameter: `update[\u003ctable\u003e][values][\u003ccolumn\u003e] = \u003cvalue\u003e`\n- Multiple update parameter conditions: `update[\u003ctable\u003e][where][\u003ccolumn\u003e] = \u003cvalue\u003e`\n\n**Note**: At the moment you can update only one row for table\n\n**Examples of PUT Requests:**\n\n**Single Update:**\n\n```http\nPUT /dataset/users/1.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n\nupdate['username']=Marco\u0026update['email']=cesarato.developer@gmail.com\u0026update['password']=3vwjehvdfjhefejjvw\u0026update['is_active']=1\n```\n\n**Multi-table Update:**\n\n```http\nPUT /dataset.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n\nupdate[users][values][username]=Marco\u0026update[users][values][email]=cesarato.developer@gmail.com\u0026update[users][where][id]=1\u0026update[cities][values][name]=Padova\u0026update[cities][where][id]=1\n```\n\n**Multiple Update:**\n\n```http\nPUT /dataset.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n\nupdate[users][][values][username]=Marco\u0026update[users][][values][email]=cesarato.developer@gmail.com\u0026update[users][][where][id]=1\u0026update[cities][][values][name]=Padova\u0026update[cities][][where][id]=1\u0026update[cities][][values][name]=Milano\u0026update[cities][][where][id]=2\n```\n\n\n\n## DELETE Request\n\nDelete data\n\n- Select the row on table: `/[database]/[table]/[id].[format]`\n\n**Examples of DELETE Requests:**\n\n```http\nDELETE /dataset/users/1.json HTTP/1.1\nHost: localhost\nAccess-Token: b279fb1d0708ed81e7a194e0c5d928b6\n```\n\n## Hooks\n\nFor write hooks you can use `plugins/custom` folder or edit manually the examples on `plugins/actions.php` or `plugins/filters.php`\n\nRemember to name file like this pattern: `[FILENAME].hooks.php` or it will not be included automatically (else you can include it manually)\n\n\n### Tips\n\nYou can use this code for have a database instance and the current user authenticated row:\n\n```php\n$user = Auth::getUser(); // User row\n$db = API::getDatabase('dataset'); // You can specify dataset. Return PDO Object\n```\n\n### Hooks list\n\nhttps://github.com/marcocesarato/Database-Web-API/wiki/3.2)-Hooks:-List\n\n### Most important hooks\n\n| Hook                  | Type   | Description                                                     | Params                                                     | Return |\n|-----------------------|--------|-----------------------------------------------------------------|------------------------------------------------------------|--------|\n| sql_restriction       | Filter | Add restriction on where conditions for each query              | (string) $restriction (string) $table (string) $permission | String |\n| can_read              | Filter | Return if can get/select                                        | (bool) $permission = true                                  | Bool   |\n| can_write             | Filter | Return if can post/insert                                       | (bool) $permission = true                                  | Bool   |\n| can_edit              | Filter | Return if can put/update                                        | (bool) $permission = true                                  | Bool   |\n| can_delete            | Filter | Return if can delete                                            | (bool) $permission = true                                  | Bool   |\n| on_read               | Filter | Result content returned on get/read                             | (array) $data (string) $table                              | Array  |\n| on_write              | Filter | Result content returned on post/write                           | (array) $data (string) $table                              | Array  |\n| on_edit               | Filter | Result content returned on put/edit                             | (array) $data (string) $table                              | Array  |\n| on_delete             | Filter | Get result content returned on delete                           | (array) $data (string) $table                              | Array  |\n| render                | Filter | Manipulate data response rendered                               | (array) $data (string) $query (string) $method             | Array  |\n\n### Hooks detail\n* Filter: `sql_restriction`\n\n  **Options of *$permission*:**\n\n  ```php\n  case 'READ':\n  case 'EDIT':\n  case 'DELETE':\n  ```\n  **Return**\n\n  ```php\n  // All denied\n  $sql = \"'1' = '0'\";\n  // All allowed\n  $sql = \"'1' = '1'\";\n  ```\n  **Examples:**\n\n  ```php\n  // Only Created\n  $sql = 'created_by = '.$user['id'];\n  // Only Team\n  $sql = 'created_by IN ('.implode(',',$teams_ids).')';\n  ```\n\n## Clients\n\n### PHP Client \n\n**Filename:** `apiclient.class.php`\n\n**Class name:** APIClient\n\n| Method           | Description                                        | Type              | Parameters                         | Return                                         |\n| ---------------- | -------------------------------------------------- | ----------------- | ---------------------------------- | ---------------------------------------------- |\n| getInstance      |                                                    | public\u003cbr\u003estatic  |                                    | Returns static reference to the class instance |\n| isConnected      | Is Connected                                       | public            |                                    | bool                                           |\n| setUrl           | Set Url                                            | public\u003cbr\u003estatic  | string $url                               |                                                |\n| setAccessToken   | Set Access token                                   | public\u003cbr\u003estatic  | string $token                             |                                                |\n| setDataset       | Set Dataset                                            | public\u003cbr\u003estatic  | string $dataset                               |                                                |\n| setTimeout       | Set Timeout                                        | public\u003cbr\u003estatic  | int $timeout = 15                           |                                                |\n| setExecutionTime | Set max execution time                              | public\u003cbr\u003estatic  | int $time = 60                              |                                                |\n| get              | Get data                                           | public            | string $table\u003cbr\u003earray $where       | bool\u003cbr\u003emixed                                  |\n| insert           | Insert data                                        | public            | array $params                      | bool\u003cbr\u003emixed                                  |\n| update           | Update data                                        | public            | array $params                      | bool\u003cbr\u003emixed                                  |\n| replace          | Replace data                                       | public            | array $params                      | bool\u003cbr\u003emixed                                  |\n| delete           | Delete data                                        | public            | string $table\u003cbr\u003earray $params      | bool\u003cbr\u003emixed                                  |\n| searchElement    | Search object in array                             | public            | $array\u003cbr\u003e$key\u003cbr\u003e$value           | mixed                                          |\n| filterBy         | Filter object in array                             | public            | $key\u003cbr\u003e$value\u003cbr\u003e$array\u003cbr\u003e$limit | mixed                                          |\n| filter           | Filter object in array                             | public            | $values\u003cbr\u003e$array\u003cbr\u003e$limit        | mixed                                          |\n\n\n## Credits\n\nhttps://github.com/project-open-data/db-to-api\n\n\u003chttps://github.com/voku/php-hooks\u003e","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcocesarato%2Fdatabase-web-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcocesarato%2Fdatabase-web-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcocesarato%2Fdatabase-web-api/lists"}