Skip to content

Commit e893f97

Browse files
added readme and license
1 parent 1457086 commit e893f97

File tree

4 files changed

+83
-33
lines changed

4 files changed

+83
-33
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Navneet Chauhan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# using PHP MVC REST API
2+
3+
Representational state transfer (REST) is a software architectural that seperates models, views and controller component and interconnectes them. it is a client-server architecture.
4+
5+
# Project Overview
6+
7+
This project is created for getting simple knowledge of php with MVC framework.
8+
9+
Project includes PHP as a backend language and MySql database.
10+
11+
Project includes email Authentication and CRUD operation on different records.
12+
13+
# Connection with MySql using PHP
14+
15+
```php
16+
class Model {
17+
protected $connection = "";
18+
protected $servername="localhost";
19+
protected $username="root";
20+
protected $password=""; // your mysql database password
21+
protected $dbname=""; // database name
22+
23+
// connecting with database
24+
function __construct() {
25+
mysqli_report(MYSQLI_REPORT_STRICT);
26+
try {
27+
$this->connection = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
28+
} catch(Exception $e) {
29+
echo "Connection to database is failed".$e->getMessage();
30+
exit;
31+
}
32+
}
33+
}
34+
```
35+
36+
# Calling Model components from Controller
37+
38+
```php
39+
require_once('Models/Model.php');
40+
session_start();
41+
42+
class Controller extends Model {
43+
function __construct() {
44+
parent::__construct();
45+
$baseDir = basename(__FILE__);
46+
$location = substr($_SERVER['PHP_SELF'], strpos($_SERVER['PHP_SELF'], $baseDir) + strlen($baseDir));
47+
if($location) {
48+
switch($location) {
49+
// cases ..
50+
}
51+
}
52+
}
53+
}
54+
```

app/Controllers/Controller.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ function test_input($data) {
1414

1515
function __construct() {
1616
parent::__construct();
17-
$whatToUse = basename(__FILE__);
18-
$t = substr($_SERVER['PHP_SELF'], strpos($_SERVER['PHP_SELF'], $whatToUse) + strlen($whatToUse));
19-
if($t) {
20-
switch($t) {
17+
$baseDir = basename(__FILE__);
18+
$location = substr($_SERVER['PHP_SELF'], strpos($_SERVER['PHP_SELF'], $baseDir) + strlen($baseDir));
19+
if($location) {
20+
switch($location) {
2121
case 'ct/app/index.php/':
2222
if ($_SERVER["REQUEST_METHOD"] == "POST") {
2323
$enrollment = $_POST["enrollment"];

app/Models/Model.php

+4-29
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ class Model {
33
protected $connection = "";
44
protected $servername="localhost";
55
protected $username="root";
6-
protected $password="nav@123";
7-
protected $dbname="navneetch";
6+
protected $password=""; // your mysql database password
7+
protected $dbname=""; // database name
88

9+
// connecting with database
910
function __construct() {
1011
mysqli_report(MYSQLI_REPORT_STRICT);
1112
try {
@@ -16,33 +17,7 @@ function __construct() {
1617
}
1718
}
1819

19-
// prepared & build - create
20-
// const $create = $conn->prepare("INSERT INTO USERS (name, enrollment, phone, semester, department, password, skills) VALUES (?, ?, ?, ?,?, ?, ?)");
21-
// const $create->bind_param("sssssss", $name, $enrollment, $phone, $semester, $department, $password, $skills);
22-
23-
24-
// const $createData = $conn->prepare("INSERT INTO TEAMS (enrollment,prblmsmt,eventname,mrequired, phone) VALUES (?, ?, ?, ?,?)");
25-
// const $createData->bind_param("sssss", $enrollment,$prblmsmt,$eventname,$mrequired, $phone);
26-
27-
// prepared & build - read
28-
// const $read = $conn->prepare("SELECT * FROM USERS");
29-
30-
// const $profileQ = $conn->prepare("SELECT * FROM TEAMS WHERE enrollment=?");
31-
// const $profileQ->bind_param("s", $enrollment);
32-
33-
// const $loginQ = $conn->prepare("SELECT * FROM USERS WHERE enrollment=?");
34-
// const $loginQ->bind_param("s", $enrollment);
35-
36-
// const $homeQ = $conn->prepare("SELECT * FROM TEAMS JOIN USERS ON TEAMS.enrollment=USERS.enrollment");
37-
38-
39-
// prepared & build - delete
40-
// const $delete = $conn->prepare("DELETE FROM TEAMS WHERE teamid=?");
41-
// const $delete->bind_param("s", $teamid);
42-
43-
// prepared & build - update
44-
// $update = $conn->prepare("UPDATE TEAMS SET prblmsmt=?, eventname=?, mrequired=? WHERE teamid=?");
45-
// $update->bind_param("ssss", $prblmsmt, $eventname, $mrequired, $teamid);
20+
// utilites for the database
4621

4722
function userLogin($enrollment, $password) {
4823
if(!empty($enrollment) && !empty($password)) {

0 commit comments

Comments
 (0)