click below
click below
Normal Size Small Size show me how
PHP - Week 4
WTWD 410 - Additional PHP & Database Vocabulary
| Term | Definition | Example |
|---|---|---|
| Session | A way to store information (in variables) to be used across multiple pages. Unlike cookies, session data is stored on the server. Sessions are used to maintain state and user information across multiple requests. | session_start(); $_SESSION["user"] = "JohnDoe"; echo $_SESSION["user"]; session_unset(); session_destroy(); |
| CRUD | An acronym for the four basic operations performed on databases: Create, Read, Update, and Delete. | // Create $sql = "INSERT INTO users (name, email) VALUES ('Bob', 'bob@email.com')"; // Read $sql = "SELECT * FROM users"; // Update $sql = "UPDATE users SET email='bob2@email.com' WHERE name='Bob'"; // Delete $sql = "DELETE FROM users WHERE name='Bob'"; |
| NoSQL | A type of database that does not use traditional SQL queries for data manipulation. NoSQL databases are designed for specific data models and have flexible schemas for building modern applications. | // Using MongoDB (a NoSQL database) db.users.insertOne({ name: "Alice", email: "alice@example.com" }); db.users.find({ name: "Alice" }); |
| MariaDB | An open-source relational database management system, forked from MySQL, that is developed by the original developers of MySQL. | $conn = new mysqli("localhost", "user", "pass", "dbname"); |
| PostgreSQL | An advanced, open-source relational database management system known for its robustness, extensibility, and standards compliance. | $conn = pg_connect("host=localhost dbname=mydb user=myuser password=mypass"); |
| SQLite | A C library that provides a lightweight, disk-based database that doesn’t require a separate server process and allows access to the database using a nonstandard variant of the SQL query language. | $db = new SQLite3('my_database.db'); $result = $db->query('SELECT * FROM users'); |
| MongoDB | A popular, open-source NoSQL database known for its flexibility and scalability. It stores data in JSON-like documents. | db.users.insertOne({ name: "Alice", email: "alice@example.com" }); |
| Mongoose | An Object Data Modeling (ODM) library for MongoDB and Node.js. It provides a schema-based solution to model application data. | const mongoose = require('mongoose'); const userSchema = new mongoose.Schema({ name: String, email: String }); const User = mongoose.model('User', userSchema); |
| Cookie | A small piece of data stored on the client's computer by the web browser while browsing a website. Cookies are used to remember information about the user, such as login status or preferences, across different sessions. | // Setting a cookie setcookie("user", "John Doe", time() + (86400 * 30), "/"); // 86400 = 1 day // Accessing a cookie if(isset($_COOKIE["user"])) { echo "User is " . $_COOKIE["user"]; } else { echo "User is not set"; } |
| CRUD Job | Refers to the implementation of Create, Read, Update, and Delete operations in a job management context, such as managing job listings, job applications, or any job-related data within a database. | // Create $sql = "INSERT INTO jobs (title, info) VALUES ('Web Developer, 'Code Website')"; // Read $sql = "SELECT * FROM jobs"; // Update $sql = "UPDATE jobs SET title='Sr. Web Developer' WHERE id=1"; // Delete $sql = "DELETE FROM jobs WHERE id=1"; |
| POST | A method used to send data to the server to create/update a resource. The data sent using the POST method is not visible in the URL and has no size limitations. | // PHP to handle POST request <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST["username"]; echo "Username is " . $username; } ?> |
| GET | A method used to request data from a specified resource. The data sent using the GET method is appended to the URL and visible in the browser’s address bar, suitable for non-sensitive data. | // PHP to handle GET request <?php if ($_SERVER["REQUEST_METHOD"] == "GET") { $username = $_GET["username"]; echo "Username is " . $username; } ?> |
| PUT | A method used to send data to the server to create or update a resource. PUT requests typically include data in the request body and are idempotent, meaning multiple identical requests will have the same effect as a single request. | // Using cURL to send a PUT request in PHP $url = ' $data = json_encode(array('name' => 'Updated Name')); $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data |
| DELETE | A method used to delete a specified resource. DELETE requests are also idempotent, meaning multiple identical requests will have the same effect as a single request. | curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => json_encode(['name' => 'Updated']), CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json'] ]); |