An open API service indexing awesome lists of open source software.

https://github.com/mehr1300/php_backend_mysql_pdo

php backend mysql and pdo
https://github.com/mehr1300/php_backend_mysql_pdo

api backend mysql pdo php php8

Last synced: about 1 year ago
JSON representation

php backend mysql and pdo

Awesome Lists containing this project

README

          

# Complete PHP Backend Project with MySQL Database

This project is a full-featured backend built with PHP, utilizing a MySQL database and PDO for secure database interactions.

### Updates 1.2.4:
- **Add And Update `PD::Transaction`**.
- **Add `Validate::Number`**.
- **Add `Sanitizer::Site`**.
- **Add `Sanitizer::Image`**.
- **Updated the `header.php` file**.
- **Updated the `configs-example.php` file**.
- **Updated the `auth.php` file**.
- **Updated the `baseClass.php` file**.

### Updates 1.2.3:
- **Removed the `CreatePagingNumber` class** due to redundancy with `Paging`.
- **Updated the `configs-example` file**.
- **Fixed issue with token** in `$GLOBALS['token_contents']` and corrected it to `$GLOBALS[TOKEN_NAME]`.

## Updates 1.2.2
- **Fixed path error when function is missing**
- Add **Transaction**
- Add in class Base **IssetCustom**
- Add in class Base::IssetCustom **type money**

## Updates 1.2.1
- **Fixed path error when function is missing**
- Resolved **authentication** issues
- Simplified and improved user authentication **security**
- Changed the process and functionality of retrieving data in different input types using **Base::Isset**
- Added **Base::SetData**
- Renamed **ReturnError** to **SetError**
- add Support **UUID**

## Prerequisites

- **PHP** version 8 or higher
- **MySQL** version 5.6 or higher
- **XAMPP** or any other local web server

## Installation

1. **Clone or Download the Project:**

Begin by cloning the project or downloading its files.

```bash
git clone https://github.com/mehr1300/php_backend_mysql_pdo.git
```

2. **Move Files to the Web Server Directory:**

Place the project files in the `htdocs` folder of **XAMPP** or the relevant directory of your web server.

3. **Database Configuration:**

- Rename the file `config-example.php` to `config.php`.
- Open `config.php` and enter your database information:

```php

















```

- **Linux and cPanel:**

- Create a `.htaccess` file in the root directory of your project and insert the following content:

```apache
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* interfaces/site/index.php [L]
```

**Explanation:**

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.

6. **Assets Folder:**

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:

- `tbl_logs.sql`
- `tbl_properties.sql`
- `tbl_user_meta_data.sql`
- `web.config`
- `.htaccess`

You can execute the SQL scripts to create the necessary tables in your database and use the configuration files for server setup as required.

## Database Tables

This project requires the creation of three tables in your MySQL database to function correctly. Execute the following SQL statements to create them:

1. **tbl_logs**

This table is used to store system logs and reports.

```sql
CREATE TABLE `nt_backend_db`.`tbl_logs` (
`log_id` int NOT NULL AUTO_INCREMENT,
`log_type` int NULL DEFAULT NULL,
`log_from` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,
`log_details` longtext CHARACTER SET utf16 COLLATE utf16_general_ci NULL,
`log_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`ip` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,
`user_agent` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,
PRIMARY KEY (`log_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf16 COLLATE = utf16_general_ci ROW_FORMAT = Dynamic;
```

2. **tbl_properties**

This table stores system settings and configurations.

```sql
CREATE TABLE `nt_backend_db`.`tbl_properties` (
`id` int NOT NULL AUTO_INCREMENT,
`last_change` varchar(11) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,
`key_category` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,
`key_name` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,
`key_value` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf16 COLLATE = utf16_general_ci ROW_FORMAT = Dynamic;
```

3. **tbl_user_meta_data**

This table stores metadata and user request information.

```sql
CREATE TABLE `nt_backend_db`.`tbl_user_meta_data` (
`meta_id` int NOT NULL AUTO_INCREMENT,
`request_method` varchar(5) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,
`user_ip` varchar(20) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,
`user_agent` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,
`meta_type` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NULL DEFAULT NULL,
`meta_info` text CHARACTER SET utf16 COLLATE utf16_general_ci NULL,
`meta_create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`meta_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf16 COLLATE = utf16_general_ci ROW_FORMAT = Dynamic;
```

**Important Notes:**

- **Executing the Scripts:** Run the above SQL statements in your database management tool (like phpMyAdmin) to create the necessary tables.
- **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.
- **Purpose of Tables:** These tables are critical for logging system activities, managing settings, and storing user metadata, ensuring the framework functions properly.

## Usage

### The `PD` Class

```php
this is a url for my post
// Output => this_is_a_url_for_my_post

// Using the Url method with an additional string appended
$url2 = Sanitizer::Url($_POST['title'], "special_string");
// Input => this is a url for my post
// Output => this_is_a_url_for_my_post_special_string

// Using the ImageName method to create a safe and standard image file name
$imageName = Sanitizer::ImageName($_FILES['image']['name']);
// Input => this is an image name
// Output => this_is_an_image_name

// Using the ImageName method with an additional string appended
$imageName = Sanitizer::ImageName($_FILES['image']['name'], "special_string");
// Input => this is an image name
// Output => this_is_an_image_name_special_string

// Using the TextArea method to sanitize multiline text input
$comment = Sanitizer::TextArea($_POST['comment']);

// Using the TextEditor method to sanitize rich text editor input
$content = Sanitizer::TextEditor($_POST['content']);
```

#### Descriptions

- **`Sanitizer::Number($num):`** Converts the input to an integer.
- **`Sanitizer::Char($value):`** Sanitizes string input by removing harmful characters.
- **`Sanitizer::Url($value, $string):`** Cleans the input and formats it for use as a URL.
- **`Sanitizer::ImageName($value, $string):`** Cleans the input and formats it for use as an image filename.
- **`Sanitizer::TextArea($value):`** Sanitizes text input from a textarea.
- **`Sanitizer::TextEditor($value):`** Sanitizes content from a rich text editor.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.

## Support

If you have any questions or issues, please open an issue on the project's GitHub repository.

## Author

- **Mehr** - [GitHub](https://github.com/mehr1300)

---

[GitHub Repository](https://github.com/mehr1300/php_backend_mysql_pdo)