Skip to content

[Feature]: Add php Course #3835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions courses/php/Overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
### PHP Course Outline

#### Beginner Level

**1. Introduction to PHP**
- What is PHP & Features
- Setting up the development environment

**2. Basic Syntax and Structure**
- PHP tags and basic syntax
- Operators (arithmetic, comparison, logical, assignment)

**3. Control Structures**
- Conditional statements (if, if-else, switch-case)
- Loops (for, while, do-while, foreach)

**4. Functions**
- Defining functions
- Variable scope (global vs. local)

**5. Arrays and Strings**
- Arrays
- Strings

**6. Forms and User Input**
- Forms and Input
- Validating and sanitizing user input

**7. Basic File Handling**
- Basic File Handling
- Uploading files

#### Intermediate Level

**1. Sessions and Cookies**
- sessions
- cookies

**2. Object-Oriented Programming (OOP)**
- Concept

**3. Error Handling**
- Error types (syntax, runtime, logical)
- Custom error handlers

**4. Working with XML and JSON**
- XML
- JSON

**5. Email Handling**
- Handling Email
- Working with PHPMailer

#### Advanced Level

**1. Advanced Arrays**
- Concept

**2. Advanced OOP Concepts**
- Abstract classes and interfaces
- Static properties and methods

**3. Advanced Database Interaction**
- Introduction to SQL and databases
- Introduction to NoSQL and database

**4. Web Services and APIs**
- Introduction to RESTful APIs
- Working with SOAP

**5. PHP Frameworks**
- Introduction to PHP frameworks
- MVC architecture

8 changes: 8 additions & 0 deletions courses/php/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "php",
"position": 15,
"link": {
"type": "generated-index",
"description": "Learn php."
}
}
73 changes: 73 additions & 0 deletions courses/php/advance-level/Advance-Database-iteration/NOSQL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
id: lesson-2
title: "NoSQL Database(MongoDB)"
sidebar_label: NoSQL Database
sidebar_position: 2
description: "Learn NoSQL Database in PHP"
tags: [courses,Advance-level,Introduction]
---

#### Topics Covered:
1. **Connecting to MongoDB:**
2. **Inserting Data:**
3. **Querying Data:**
4. **Updating Data:**
5. **Deleting Data:**

**Connecting to MongoDB:**

```php
<?php
require 'vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->myDatabase->users;
?>
```

**Inserting Data:**

```php
<?php
$insertOneResult = $collection->insertOne([
'username' => 'john_doe',
'email' => 'john@example.com'
]);
echo "Inserted with Object ID '{$insertOneResult->getInsertedId()}'";
?>
```

**Querying Data:**

```php
<?php
$user = $collection->findOne(['username' => 'john_doe']);
echo "User email: " . $user['email'];
?>
```

**Updating Data:**

```php
<?php
$updateResult = $collection->updateOne(
['username' => 'john_doe'],
['$set' => ['email' => 'john_updated@example.com']]
);
echo "Matched {$updateResult->getMatchedCount()} document(s)\n";
echo "Modified {$updateResult->getModifiedCount()} document(s)\n";
?>
```

**Deleting Data:**

```php
<?php
$deleteResult = $collection->deleteOne(['username' => 'john_doe']);
echo "Deleted {$deleteResult->getDeletedCount()} document(s)\n";
?>
```


:::tip
- When working with NoSQL databases like MongoDB, leverage its flexible schema and powerful querying capabilities.
:::
210 changes: 210 additions & 0 deletions courses/php/advance-level/Advance-Database-iteration/SQL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
---
id: lesson-1
title: "SQL Database"
sidebar_label: SQL Database
sidebar_position: 1
description: "Learn SQL Database in PHP"
tags: [courses,Advance-level,Introduction]
---


#### Topics Covered:
1. Introduction to SQL and Databases
2. Connecting to a Database with PHP (MySQL, PDO)
3. Performing CRUD Operations (Create, Read, Update, Delete)
4. Prepared Statements and Parameter Binding

### Flowchart

```mermaid
graph TD
A[Start]
B{Choose CRUD Operation}
C[Create => INSERT]
D[Read => SELECT]
E[Update => UPDATE]
F[Delete => DELETE]
G[Insert new record into database]
H[Fetch records from database]
I[Update existing record in database]
J[Delete record from database]

A --> B
B -->|Create| C
B -->|Read| D
B -->|Update| E
B -->|Delete| F
C --> G
D --> H
E --> I
F --> J
```

### 1. Introduction to SQL and Databases

**SQL (Structured Query Language):**
- SQL is used to communicate with databases. It is the standard language for relational database management systems.

**Basic SQL Commands:**
- **CREATE DATABASE:** Creates a new database.
- **CREATE TABLE:** Creates a new table in the database.
- **INSERT INTO:** Inserts new data into a table.
- **SELECT:** Retrieves data from a database.
- **UPDATE:** Updates existing data within a table.
- **DELETE:** Deletes data from a table.

```sql
-- Example SQL Commands
CREATE DATABASE myDatabase;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL
);

INSERT INTO users (username, email) VALUES ('john_doe', 'john@example.com');
SELECT * FROM users;
UPDATE users SET email='john_updated@example.com' WHERE username='john_doe';
DELETE FROM users WHERE username='john_doe';
```

### 2. Connecting to a Database with PHP (MySQL, PDO)

**Using MySQLi:**

```php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDatabase";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
```

**Using PDO:**

```php
<?php
$dsn = 'mysql:host=localhost;dbname=myDatabase';
$username = 'root';
$password = '';

try {
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
```

### 3. Performing CRUD Operations (Create, Read, Update, Delete)

**Create (INSERT):**

```php
<?php
$sql = "INSERT INTO users (username, email) VALUES ('jane_doe', 'jane@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
?>
```

**Read (SELECT):**

```php
<?php
$sql = "SELECT id, username, email FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["username"]. " - Email: " . $row["email"]. "<br>";
}
} else {
echo "0 results";
}
?>
```

**Update (UPDATE):**

```php
<?php
$sql = "UPDATE users SET email='jane_updated@example.com' WHERE username='jane_doe'";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
?>
```

**Delete (DELETE):**

```php
<?php
$sql = "DELETE FROM users WHERE username='jane_doe'";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
?>
```

### 4. Prepared Statements and Parameter Binding

**Using MySQLi:**

```php
<?php
$stmt = $conn->prepare("INSERT INTO users (username, email) VALUES (?, ?)");
$stmt->bind_param("ss", $username, $email);

$username = "mike_doe";
$email = "mike@example.com";
$stmt->execute();

echo "New records created successfully";

$stmt->close();
$conn->close();
?>
```

**Using PDO:**

```php
<?php
$stmt = $pdo->prepare("INSERT INTO users (username, email) VALUES (:username, :email)");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':email', $email);

$username = "anna_doe";
$email = "anna@example.com";
$stmt->execute();

echo "New records created successfully";
?>
```

:::tip
- Always use prepared statements to protect against SQL injection.
- Choose PDO over MySQLi for more flexibility and support for multiple databases.
- Properly handle errors and exceptions to debug issues effectively.
- Keep your database connection credentials secure and avoid hardcoding them in your scripts.
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Working with Databases",
"position": 3,
"link": {
"type": "generated-index",
"description": "Learn Advanced Database Iteration."
}
}
Loading
Loading