Skip to content

Commit 694b9d6

Browse files
authored
Merge pull request #3835 from sivaprasath2004/sivaprasath-closes-issue-3802
[Feature]: Add php Course
2 parents 5415dc2 + 34707b8 commit 694b9d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4051
-0
lines changed

courses/php/Overview.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
### PHP Course Outline
2+
3+
#### Beginner Level
4+
5+
**1. Introduction to PHP**
6+
- What is PHP & Features
7+
- Setting up the development environment
8+
9+
**2. Basic Syntax and Structure**
10+
- PHP tags and basic syntax
11+
- Operators (arithmetic, comparison, logical, assignment)
12+
13+
**3. Control Structures**
14+
- Conditional statements (if, if-else, switch-case)
15+
- Loops (for, while, do-while, foreach)
16+
17+
**4. Functions**
18+
- Defining functions
19+
- Variable scope (global vs. local)
20+
21+
**5. Arrays and Strings**
22+
- Arrays
23+
- Strings
24+
25+
**6. Forms and User Input**
26+
- Forms and Input
27+
- Validating and sanitizing user input
28+
29+
**7. Basic File Handling**
30+
- Basic File Handling
31+
- Uploading files
32+
33+
#### Intermediate Level
34+
35+
**1. Sessions and Cookies**
36+
- sessions
37+
- cookies
38+
39+
**2. Object-Oriented Programming (OOP)**
40+
- Concept
41+
42+
**3. Error Handling**
43+
- Error types (syntax, runtime, logical)
44+
- Custom error handlers
45+
46+
**4. Working with XML and JSON**
47+
- XML
48+
- JSON
49+
50+
**5. Email Handling**
51+
- Handling Email
52+
- Working with PHPMailer
53+
54+
#### Advanced Level
55+
56+
**1. Advanced Arrays**
57+
- Concept
58+
59+
**2. Advanced OOP Concepts**
60+
- Abstract classes and interfaces
61+
- Static properties and methods
62+
63+
**3. Advanced Database Interaction**
64+
- Introduction to SQL and databases
65+
- Introduction to NoSQL and database
66+
67+
**4. Web Services and APIs**
68+
- Introduction to RESTful APIs
69+
- Working with SOAP
70+
71+
**5. PHP Frameworks**
72+
- Introduction to PHP frameworks
73+
- MVC architecture
74+

courses/php/_category_.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "php",
3+
"position": 15,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn php."
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
id: lesson-2
3+
title: "NoSQL Database(MongoDB)"
4+
sidebar_label: NoSQL Database
5+
sidebar_position: 2
6+
description: "Learn NoSQL Database in PHP"
7+
tags: [courses,Advance-level,Introduction]
8+
---
9+
10+
#### Topics Covered:
11+
1. **Connecting to MongoDB:**
12+
2. **Inserting Data:**
13+
3. **Querying Data:**
14+
4. **Updating Data:**
15+
5. **Deleting Data:**
16+
17+
**Connecting to MongoDB:**
18+
19+
```php
20+
<?php
21+
require 'vendor/autoload.php'; // include Composer's autoloader
22+
$client = new MongoDB\Client("mongodb://localhost:27017");
23+
$collection = $client->myDatabase->users;
24+
?>
25+
```
26+
27+
**Inserting Data:**
28+
29+
```php
30+
<?php
31+
$insertOneResult = $collection->insertOne([
32+
'username' => 'john_doe',
33+
'email' => '[email protected]'
34+
]);
35+
echo "Inserted with Object ID '{$insertOneResult->getInsertedId()}'";
36+
?>
37+
```
38+
39+
**Querying Data:**
40+
41+
```php
42+
<?php
43+
$user = $collection->findOne(['username' => 'john_doe']);
44+
echo "User email: " . $user['email'];
45+
?>
46+
```
47+
48+
**Updating Data:**
49+
50+
```php
51+
<?php
52+
$updateResult = $collection->updateOne(
53+
['username' => 'john_doe'],
54+
['$set' => ['email' => '[email protected]']]
55+
);
56+
echo "Matched {$updateResult->getMatchedCount()} document(s)\n";
57+
echo "Modified {$updateResult->getModifiedCount()} document(s)\n";
58+
?>
59+
```
60+
61+
**Deleting Data:**
62+
63+
```php
64+
<?php
65+
$deleteResult = $collection->deleteOne(['username' => 'john_doe']);
66+
echo "Deleted {$deleteResult->getDeletedCount()} document(s)\n";
67+
?>
68+
```
69+
70+
71+
:::tip
72+
- When working with NoSQL databases like MongoDB, leverage its flexible schema and powerful querying capabilities.
73+
:::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
---
2+
id: lesson-1
3+
title: "SQL Database"
4+
sidebar_label: SQL Database
5+
sidebar_position: 1
6+
description: "Learn SQL Database in PHP"
7+
tags: [courses,Advance-level,Introduction]
8+
---
9+
10+
11+
#### Topics Covered:
12+
1. Introduction to SQL and Databases
13+
2. Connecting to a Database with PHP (MySQL, PDO)
14+
3. Performing CRUD Operations (Create, Read, Update, Delete)
15+
4. Prepared Statements and Parameter Binding
16+
17+
### Flowchart
18+
19+
```mermaid
20+
graph TD
21+
A[Start]
22+
B{Choose CRUD Operation}
23+
C[Create => INSERT]
24+
D[Read => SELECT]
25+
E[Update => UPDATE]
26+
F[Delete => DELETE]
27+
G[Insert new record into database]
28+
H[Fetch records from database]
29+
I[Update existing record in database]
30+
J[Delete record from database]
31+
32+
A --> B
33+
B -->|Create| C
34+
B -->|Read| D
35+
B -->|Update| E
36+
B -->|Delete| F
37+
C --> G
38+
D --> H
39+
E --> I
40+
F --> J
41+
```
42+
43+
### 1. Introduction to SQL and Databases
44+
45+
**SQL (Structured Query Language):**
46+
- SQL is used to communicate with databases. It is the standard language for relational database management systems.
47+
48+
**Basic SQL Commands:**
49+
- **CREATE DATABASE:** Creates a new database.
50+
- **CREATE TABLE:** Creates a new table in the database.
51+
- **INSERT INTO:** Inserts new data into a table.
52+
- **SELECT:** Retrieves data from a database.
53+
- **UPDATE:** Updates existing data within a table.
54+
- **DELETE:** Deletes data from a table.
55+
56+
```sql
57+
-- Example SQL Commands
58+
CREATE DATABASE myDatabase;
59+
CREATE TABLE users (
60+
id INT AUTO_INCREMENT PRIMARY KEY,
61+
username VARCHAR(50) NOT NULL,
62+
email VARCHAR(100) NOT NULL
63+
);
64+
65+
INSERT INTO users (username, email) VALUES ('john_doe', '[email protected]');
66+
SELECT * FROM users;
67+
UPDATE users SET email='[email protected]' WHERE username='john_doe';
68+
DELETE FROM users WHERE username='john_doe';
69+
```
70+
71+
### 2. Connecting to a Database with PHP (MySQL, PDO)
72+
73+
**Using MySQLi:**
74+
75+
```php
76+
<?php
77+
$servername = "localhost";
78+
$username = "root";
79+
$password = "";
80+
$dbname = "myDatabase";
81+
82+
// Create connection
83+
$conn = new mysqli($servername, $username, $password, $dbname);
84+
85+
// Check connection
86+
if ($conn->connect_error) {
87+
die("Connection failed: " . $conn->connect_error);
88+
}
89+
echo "Connected successfully";
90+
?>
91+
```
92+
93+
**Using PDO:**
94+
95+
```php
96+
<?php
97+
$dsn = 'mysql:host=localhost;dbname=myDatabase';
98+
$username = 'root';
99+
$password = '';
100+
101+
try {
102+
$pdo = new PDO($dsn, $username, $password);
103+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
104+
echo "Connected successfully";
105+
} catch (PDOException $e) {
106+
echo "Connection failed: " . $e->getMessage();
107+
}
108+
?>
109+
```
110+
111+
### 3. Performing CRUD Operations (Create, Read, Update, Delete)
112+
113+
**Create (INSERT):**
114+
115+
```php
116+
<?php
117+
$sql = "INSERT INTO users (username, email) VALUES ('jane_doe', '[email protected]')";
118+
if ($conn->query($sql) === TRUE) {
119+
echo "New record created successfully";
120+
} else {
121+
echo "Error: " . $sql . "<br>" . $conn->error;
122+
}
123+
?>
124+
```
125+
126+
**Read (SELECT):**
127+
128+
```php
129+
<?php
130+
$sql = "SELECT id, username, email FROM users";
131+
$result = $conn->query($sql);
132+
133+
if ($result->num_rows > 0) {
134+
while($row = $result->fetch_assoc()) {
135+
echo "id: " . $row["id"]. " - Name: " . $row["username"]. " - Email: " . $row["email"]. "<br>";
136+
}
137+
} else {
138+
echo "0 results";
139+
}
140+
?>
141+
```
142+
143+
**Update (UPDATE):**
144+
145+
```php
146+
<?php
147+
$sql = "UPDATE users SET email='[email protected]' WHERE username='jane_doe'";
148+
if ($conn->query($sql) === TRUE) {
149+
echo "Record updated successfully";
150+
} else {
151+
echo "Error updating record: " . $conn->error;
152+
}
153+
?>
154+
```
155+
156+
**Delete (DELETE):**
157+
158+
```php
159+
<?php
160+
$sql = "DELETE FROM users WHERE username='jane_doe'";
161+
if ($conn->query($sql) === TRUE) {
162+
echo "Record deleted successfully";
163+
} else {
164+
echo "Error deleting record: " . $conn->error;
165+
}
166+
?>
167+
```
168+
169+
### 4. Prepared Statements and Parameter Binding
170+
171+
**Using MySQLi:**
172+
173+
```php
174+
<?php
175+
$stmt = $conn->prepare("INSERT INTO users (username, email) VALUES (?, ?)");
176+
$stmt->bind_param("ss", $username, $email);
177+
178+
$username = "mike_doe";
179+
$email = "[email protected]";
180+
$stmt->execute();
181+
182+
echo "New records created successfully";
183+
184+
$stmt->close();
185+
$conn->close();
186+
?>
187+
```
188+
189+
**Using PDO:**
190+
191+
```php
192+
<?php
193+
$stmt = $pdo->prepare("INSERT INTO users (username, email) VALUES (:username, :email)");
194+
$stmt->bindParam(':username', $username);
195+
$stmt->bindParam(':email', $email);
196+
197+
$username = "anna_doe";
198+
$email = "[email protected]";
199+
$stmt->execute();
200+
201+
echo "New records created successfully";
202+
?>
203+
```
204+
205+
:::tip
206+
- Always use prepared statements to protect against SQL injection.
207+
- Choose PDO over MySQLi for more flexibility and support for multiple databases.
208+
- Properly handle errors and exceptions to debug issues effectively.
209+
- Keep your database connection credentials secure and avoid hardcoding them in your scripts.
210+
:::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Working with Databases",
3+
"position": 3,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn Advanced Database Iteration."
7+
}
8+
}

0 commit comments

Comments
 (0)