Skip to content

parisa-khaleghi/RESTful-API-PHP-MySQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTful API with PHP/MySQL

Create RESTful API With PHP/MySQL.

For RESTful API with PHP/MySQL. This is a full guide for you. You can use the youtube video on this link, or follow the steps bellow and use the code in this repository.

NOTE: There are 2 version of this project. The 2nd version is on ../src, ../index.php, and ..//.htaccess.

First will start with the 1st version.

Start from here

  1. In project folder, create a "core" folder and a new file "initialize.php" for all our settings.
  2. In project folder, create a "includes" folder and a new file "config.php" for database connection.
  3. Add DB connection in "config.php".
  4. Set some db attributes in "config.php".
  5. Define necessery constants in "initialize.php".
  6. Create core classes in "initialize.php" (e.g. by named 'post').
  7. Create folder in root with a file in the folder by named /api/read.php to allow HTTP request here.
  8. In read.php instantiate post class and then, get the row count and prepare output in json.
  9. Create db and tables and then, insert data in tables. you can use the sql file in sql folder in this repo.
  10. Add read_single function in post.php. Then create a new file in api/read_single.php and write the code for GET method for single row.
  11. Add 'create' function in post.php. Then create a new file in api/create.php and write the code for POST, Also, you need to add some headers.
  12. You can use the structure in POST method for PUT and DELETE.
  13. Do the same things for category table.

NOTE: If you sraggling somewhere, you can get help from the codes in this repository.

URIs

To costum URIs instead of calling the files directly, you can use this video.