WebTechnologies UNIT5
WebTechnologies UNIT5
By
K.Ramesh
Assistant Professor
Dept. of Computer Science and Engineering
Aditya University
Surampalem
UNIT - 5
• Cross-Platform Compatibility
Example: <?php
echo "Hello, World!";
?>
Web Technologies K.Ramesh, Assistant Professor
Creating and Running PHP Script
Steps to Create a PHP Script
1. Open a text editor (VS Code, Notepad++, Sublime Text).
2. Save the file with a .php extension (e.g., index.php).
3. Write PHP code inside <?php ... ?> tags.
Example: <?php
echo "Hello, World!";
?>
2. Special Types:
Array: Collection of values → ["Red", "Green", "Blue"]
Object: Instance of a class
Callable: Function as a variable
Iterable: Loops through items
3. Compound Types:
Resource: External connections like files, databases
Null: Represents a variable with no value
Web Technologies K.Ramesh, Assistant Professor
OPERATORS
• Operators in PHP are used to perform operations on variables and values.
1. Arithmetic Operators (Perform mathematical operations) +, -, 5. Increment/Decrement Operators
*, /, % ++, --
$x = 10;
$x = 5;
$y = 3;
echo ++$x; // Output: 6
echo $x + $y; // Output: 13
6. String Operator (Concatenation)
2. Assignment Operators (Assign values)
$txt1 = "Hello";
=, +=, -=, *=, /=, %=, .=
$txt2 = " World";
$x = 5;
echo $txt1 . $txt2; // Output: Hello World
$x += 3; // Equivalent to $x = $x + 3
7. Array Operators (Compare arrays)
echo $x; // Output: 8
+, ==, ===, !=, <>
3. Comparison Operators (Compare values)
$a = [1, 2, 3];
==, ===, !=, <>, !==, >, <, >=, <=
$b = [4, 5, 6];
$x = 5;
$c = $a + $b; // Union of arrays
$y = "5";
print_r($c);
echo ($x == $y); // Output: 1 (true)
8. Ternary Operator (Short if-else)
4. Logical Operators (Used for conditions)
condition ? true_value : false_value;
&&, ||, !, and, or, xor
$age = 20;
$x = true;
echo ($age >= 18) ? "Adult" : "Minor"; // Output: Adult
$y = false;
echo ($x && $y); // Output: (false)
Main Concepts:
Example:
<form action="process.php" method="POST">
<input type="text" name="username"
placeholder="Enter Name">
<input type="submit" value="Submit">
</form> Fig : PHP Form Handling Workflow
MongoDB
• MongoDB is a document-oriented NoSQL database that stores data in JSON-like
BSON format.
• Provides high availability, scalability, and flexibility.
• Uses collections (similar to tables in SQL) and documents (similar to rows in SQL).
2. Viewing Databases
Use “show dbs” to list databases (only if they contain data).
3. Dropping a Database
• Switch to the database and drop it using:
use schoolDB
db.dropDatabase()
🔹 Deletes the database and collections permanently.
Key Points
• Databases are created when data is inserted.
• show dbs lists databases with collections.
• db.dropDatabase() removes a database permanently.
Web Technologies K. Ramesh, Assistant Professor
Create and Drop Collection in MongoDB
1. Creating a Collection
• In MongoDB, collections are created automatically when you insert the first document.
• However, you can explicitly create a collection using:
db.createCollection("students")
Example (Inserting data creates a collection automatically):
db.students.insertOne({ name: "Alice", age: 22 })
2. Viewing Collections
• To list all collections in the current database:
show collections
3. Dropping a Collection
• To delete a collection permanently, use:
db.students.drop()
• This removes all documents and deletes the collection.
Key Points
• Collections are created when data is inserted.
• show collections lists all collections in the current database.
• db.collection.drop() permanently deletes a collection.
Web Technologies K. Ramesh, Assistant Professor
MongoDB Data Types
• MongoDB supports various data types that can be used to store different kinds of values in documents.
PHP + MySQL: Used for structured data storage with tables, queries, and relationships.
PHP + MongoDB: NoSQL database for flexible and scalable data storage.
Client-Server Flow: PHP processes requests, interacts with databases, and returns responses to users.