{"id":27638035,"url":"https://github.com/mehr1300/php_backend_mysql_pdo","last_synced_at":"2025-06-24T15:34:34.848Z","repository":{"id":262522940,"uuid":"887519424","full_name":"mehr1300/php_backend_mysql_pdo","owner":"mehr1300","description":"php backend mysql and pdo","archived":false,"fork":false,"pushed_at":"2025-03-25T08:49:57.000Z","size":124,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T21:40:03.051Z","etag":null,"topics":["api","backend","mysql","pdo","php","php8"],"latest_commit_sha":null,"homepage":"","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/mehr1300.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2024-11-12T21:20:37.000Z","updated_at":"2025-04-21T10:21:07.000Z","dependencies_parsed_at":"2024-11-13T20:20:58.535Z","dependency_job_id":"32dfe968-3c16-4cb9-a5ac-69b920caa600","html_url":"https://github.com/mehr1300/php_backend_mysql_pdo","commit_stats":null,"previous_names":["mehr1300/php_backent_mysql_pdo","mehr1300/php_backend_mysql_pdo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mehr1300/php_backend_mysql_pdo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehr1300%2Fphp_backend_mysql_pdo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehr1300%2Fphp_backend_mysql_pdo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehr1300%2Fphp_backend_mysql_pdo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehr1300%2Fphp_backend_mysql_pdo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehr1300","download_url":"https://codeload.github.com/mehr1300/php_backend_mysql_pdo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehr1300%2Fphp_backend_mysql_pdo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261703604,"owners_count":23196995,"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":["api","backend","mysql","pdo","php","php8"],"created_at":"2025-04-23T21:36:17.748Z","updated_at":"2025-06-24T15:34:34.789Z","avatar_url":"https://github.com/mehr1300.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Complete PHP Backend Project with MySQL Database\n\n\nThis project is a full-featured backend built with PHP, utilizing a MySQL database and PDO for secure database interactions.\n\n### Updates 1.2.4:\n- **Add And Update `PD::Transaction`**.\n- **Add  `Validate::Number`**.\n- **Add  `Sanitizer::Site`**.\n- **Add  `Sanitizer::Image`**.\n- **Updated the `header.php` file**.\n- **Updated the `configs-example.php` file**.\n- **Updated the `auth.php` file**.\n- **Updated the `baseClass.php` file**.\n\n\n\n### Updates 1.2.3:\n- **Removed the `CreatePagingNumber` class** due to redundancy with `Paging`.\n- **Updated the `configs-example` file**.\n- **Fixed issue with token** in `$GLOBALS['token_contents']` and corrected it to `$GLOBALS[TOKEN_NAME]`.\n\n\n## Updates 1.2.2\n- **Fixed path error when function is missing**\n- Add **Transaction**\n- Add in class Base **IssetCustom**\n- Add in class Base::IssetCustom **type money**\n\n\n## Updates 1.2.1\n- **Fixed path error when function is missing**\n- Resolved **authentication** issues\n- Simplified and improved user authentication **security**\n- Changed the process and functionality of retrieving data in different input types using **Base::Isset**\n- Added **Base::SetData**\n- Renamed **ReturnError** to **SetError**\n- add Support **UUID**\n\n\n## Prerequisites\n\n- **PHP** version 8 or higher\n- **MySQL** version 5.6 or higher\n- **XAMPP** or any other local web server\n\n## Installation\n\n1. **Clone or Download the Project:**\n\n   Begin by cloning the project or downloading its files.\n\n   ```bash\n   git clone https://github.com/mehr1300/php_backend_mysql_pdo.git\n   ```\n\n2. **Move Files to the Web Server Directory:**\n\n   Place the project files in the `htdocs` folder of **XAMPP** or the relevant directory of your web server.\n\n3. **Database Configuration:**\n\n   - Rename the file `config-example.php` to `config.php`.\n   - Open `config.php` and enter your database information:\n\n     ```php\n     \u003c?php\n     const SERVERNAME_DB = \"localhost\";\n     const USERNAME_DB = \"Database_username\";\n     const PASSWORD_DB = \"Database_password\";\n     const DATABASE_DB = \"Database_database\";\n     ```\n\n4. **Creating the Database:**\n\n   - Execute the MySQL file located in the `database` folder using a database management tool (like phpMyAdmin) to create the required tables.\n\n5. **Server Configuration for Routing:**\n\n   - **Windows Server:**\n\n      - Create a `web.config` file in the root directory of your project and insert the following content:\n\n        ```xml\n        \u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n        \u003cconfiguration\u003e\n          \u003csystem.webServer\u003e\n            \u003crewrite\u003e\n              \u003crules\u003e\n                \u003crule name=\"Redirect all to index.php\" stopProcessing=\"true\"\u003e\n                  \u003cmatch url=\".*\" /\u003e\n                  \u003cconditions\u003e\n                    \u003cadd input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" /\u003e\n                    \u003cadd input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" /\u003e\n                  \u003c/conditions\u003e\n                  \u003caction type=\"Rewrite\" url=\"interfaces/site/index.php\" /\u003e\n                \u003c/rule\u003e\n              \u003c/rules\u003e\n            \u003c/rewrite\u003e\n          \u003c/system.webServer\u003e\n        \u003c/configuration\u003e\n        ```\n\n   - **Linux and cPanel:**\n\n      - Create a `.htaccess` file in the root directory of your project and insert the following content:\n\n        ```apache\n        RewriteEngine On\n \n        RewriteCond %{REQUEST_FILENAME} !-f\n        RewriteCond %{REQUEST_FILENAME} !-d\n        RewriteRule .* interfaces/site/index.php [L]\n        ```\n\n   **Explanation:**\n\n   These configurations are essential for enabling URL routing in your application. They redirect all incoming requests that do not match an existing file or directory to `interfaces/site/index.php`, allowing centralized route management.\n\n6. **Assets Folder:**\n\n   A folder named `assets` is present in the root directory of the project. This folder contains the following files that you can use if needed:\n\n   - `tbl_logs.sql`\n   - `tbl_properties.sql`\n   - `tbl_user_meta_data.sql`\n   - `web.config`\n   - `.htaccess`\n\n   You can execute the SQL scripts to create the necessary tables in your database and use the configuration files for server setup as required.\n\n## Database Tables\n\nThis project requires the creation of three tables in your MySQL database to function correctly. Execute the following SQL statements to create them:\n\n1. **tbl_logs**\n\n   This table is used to store system logs and reports.\n\n   ```sql\n   CREATE TABLE `nt_backend_db`.`tbl_logs` (\n     `log_id` int NOT NULL AUTO_INCREMENT,\n     `log_type` int NULL DEFAULT NULL,\n     `log_from` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,\n     `log_details` longtext CHARACTER SET utf16 COLLATE utf16_general_ci NULL,\n     `log_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,\n     `ip` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,\n     `user_agent` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,\n     PRIMARY KEY (`log_id`) USING BTREE\n   ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf16 COLLATE = utf16_general_ci ROW_FORMAT = Dynamic;\n   ```\n\n2. **tbl_properties**\n\n   This table stores system settings and configurations.\n\n   ```sql\n   CREATE TABLE `nt_backend_db`.`tbl_properties` (\n     `id` int NOT NULL AUTO_INCREMENT,\n     `last_change` varchar(11) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,\n     `key_category` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,\n     `key_name` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,\n     `key_value` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,\n     PRIMARY KEY (`id`) USING BTREE\n   ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf16 COLLATE = utf16_general_ci ROW_FORMAT = Dynamic;\n   ```\n\n3. **tbl_user_meta_data**\n\n   This table stores metadata and user request information.\n\n   ```sql\n   CREATE TABLE `nt_backend_db`.`tbl_user_meta_data` (\n     `meta_id` int NOT NULL AUTO_INCREMENT,\n     `request_method` varchar(5) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,\n     `user_ip` varchar(20) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,\n     `user_agent` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,\n     `meta_type` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,\n     `meta_info` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,\n     `meta_create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,\n     PRIMARY KEY (`meta_id`) USING BTREE\n   ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf16 COLLATE = utf16_general_ci ROW_FORMAT = Dynamic;\n   ```\n\n**Important Notes:**\n\n- **Executing the Scripts:** Run the above SQL statements in your database management tool (like phpMyAdmin) to create the necessary tables.\n- **Table Names:** Ensure that the table names (`tbl_logs`, `tbl_properties`, `tbl_user_meta_data`) match exactly as used in the project to avoid any issues.\n- **Purpose of Tables:** These tables are critical for logging system activities, managing settings, and storing user metadata, ensuring the framework functions properly.\n\n## Usage\n\n### The `PD` Class\n\n```php\n\u003c?php\nclass PD {\n    public static function Insert($Table_Name, $Insert_Data): bool|string {//...//}\n    public static function Update(string $Table_Name, array $data, string $Condition, array $params): bool|int {//...//}\n    public static function Delete(string $Table_Name, string $Condition, array $params): bool {//...//}\n    public static function SingleSelect(string $Table_Name, string $Condition, array $params, $What_Row = 'count(*)') {//...//}\n    public static function RowSelect(string $Table_Name, string $Condition, array $params, $What_Row = \"*\") {//...//}\n    public static function MultiSelect(string $Table_Name, string $Condition, array $params, $What_Row = \"*\"): bool|array  {//...//}\n}\n```\n\n#### Example Usage of the `PD` Class\n\nBelow are some examples of how to retrieve data from the database using the `PD` class.\n\n#### `tbl_user` Table\n\n| id | firstname | lastname | gender | age |\n|----|-----------|----------|--------|-----|\n| 1  | John      | Doe      | M      | 19  |\n| 2  | Bob       | Black    | M      | 41  |\n| 3  | Zoe       | Chan     | F      | 20  |\n| 4  | Kona      | Khan     | M      | 14  |\n| 5  | Kader     | Khan     | M      | 56  |\n\n#### Retrieving All Records from a Table\n\n```php\n\u003c?php\n// Retrieve all records from the tbl_user table\n$persons = PD::MultiSelect(\"tbl_user\", \"\", []);\n```\n\n#### Retrieving Data with Conditions\n\n```php\n\u003c?php\n// Retrieve male users\n$malePersons = PD::MultiSelect(\"tbl_user\", \"WHERE gender = ?\", [\"M\"]);\n\n// Retrieve ID and firstname of male users\n$maleNames = PD::MultiSelect(\"tbl_user\", \"WHERE gender = ?\", [\"M\"], \"id, firstname\");\n```\n\n#### Retrieving a Single Row\n\nThis method returns only one row.\n\n```php\n\u003c?php\n// Retrieve user information with id 1\n$user = PD::RowSelect(\"tbl_user\", \"WHERE id = ?\", [1]);\n```\n\n##### Result\n\n| id | firstname | lastname | gender | age |\n|----|-----------|----------|--------|-----|\n| 1  | John      | Doe      | M      | 19  |\n\n#### Retrieving a Single Value\n\nThis method returns only one value.\n\n```php\n\u003c?php\n// Retrieve the firstname of the user with id 1\n$firstname = PD::SingleSelect(\"tbl_user\", \"WHERE id = ?\", [1], \"firstname\");\n```\n\n##### Result\n\n| firstname |\n|-----------|\n| John      |\n\n#### Descriptions\n\n- **`PD::Insert($Table_Name, $Insert_Data):`** Adds a new record to the table.\n- **`PD::Update(string $Table_Name, array $data, string $Condition, array $params):`** Updates existing records in the table.\n- **`PD::Delete(string $Table_Name, string $Condition, array $params):`** Deletes records from the table.\n- **`PD::SingleSelect(string $Table_Name, string $Condition, array $params, $What_Row = 'count(*)'):`** Directly retrieves a single value from the table.\n- **`PD::RowSelect(string $Table_Name, string $Condition, array $params, $What_Row = \"*\"):`** Retrieves a single row from the table.\n- **`PD::MultiSelect(string $Table_Name, string $Condition, array $params, $What_Row = \"*\"):`** Retrieves multiple records from the table.\n\n---\n\n### The `Sanitizer` Class\n\nThe `Sanitizer` class is used for cleaning and validating user inputs to prevent malicious data from entering the system.\n\n```php\n\u003c?php\nclass Sanitizer\n{\n    public static function Number($num): ?int   {//...//}\n    public static function Char($value): ?string  {//...// }\n    public static function Url($value, $string = \"\"): string{//...//}\n    public static function ImageName($value, $string = \"\"): string {//...//}\n    public static function TextArea($value): ?string {//...//}\n    public static function TextEditor($value): ?string {//...//}\n}\n```\n\n#### Example Usage of the `Sanitizer` Class\n\n```php\n\u003c?php\n// Using the Number method to sanitize numeric input\n$userId = Sanitizer::Number($_GET['id']);\n\n// Using the Char method to sanitize string input\n$username = Sanitizer::Char($_POST['username']);\n\n// Using the Url method to create a safe and standard URL\n$url = Sanitizer::Url($_POST['title']);\n// Input =\u003e this is a url for my post\n// Output =\u003e this_is_a_url_for_my_post\n\n// Using the Url method with an additional string appended\n$url2 = Sanitizer::Url($_POST['title'], \"special_string\");\n// Input =\u003e this is a url for my post\n// Output =\u003e this_is_a_url_for_my_post_special_string\n\n// Using the ImageName method to create a safe and standard image file name\n$imageName = Sanitizer::ImageName($_FILES['image']['name']);\n// Input =\u003e this is an image name\n// Output =\u003e this_is_an_image_name\n\n// Using the ImageName method with an additional string appended\n$imageName = Sanitizer::ImageName($_FILES['image']['name'], \"special_string\");\n// Input =\u003e this is an image name\n// Output =\u003e this_is_an_image_name_special_string\n\n// Using the TextArea method to sanitize multiline text input\n$comment = Sanitizer::TextArea($_POST['comment']);\n\n// Using the TextEditor method to sanitize rich text editor input\n$content = Sanitizer::TextEditor($_POST['content']);\n```\n\n#### Descriptions\n\n- **`Sanitizer::Number($num):`** Converts the input to an integer.\n- **`Sanitizer::Char($value):`** Sanitizes string input by removing harmful characters.\n- **`Sanitizer::Url($value, $string):`** Cleans the input and formats it for use as a URL.\n- **`Sanitizer::ImageName($value, $string):`** Cleans the input and formats it for use as an image filename.\n- **`Sanitizer::TextArea($value):`** Sanitizes text input from a textarea.\n- **`Sanitizer::TextEditor($value):`** Sanitizes content from a rich text editor.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.\n\n## Support\n\nIf you have any questions or issues, please open an issue on the project's GitHub repository.\n\n## Author\n\n- **Mehr** - [GitHub](https://github.com/mehr1300)\n\n---\n\n[GitHub Repository](https://github.com/mehr1300/php_backend_mysql_pdo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehr1300%2Fphp_backend_mysql_pdo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehr1300%2Fphp_backend_mysql_pdo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehr1300%2Fphp_backend_mysql_pdo/lists"}