Presentation is loading. Please wait.

Presentation is loading. Please wait.

Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE <?php session_start(); //need this before declaring a session global. echo " You.

Similar presentations


Presentation on theme: "Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE <?php session_start(); //need this before declaring a session global. echo " You."— Presentation transcript:

1 Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE <?php session_start(); //need this before declaring a session global. echo " You are on page ".$_SERVER['PHP_SELF']." "; if($_SESSION['last_page']) { echo " The page you last visited is ".$_SESSION['last_page']; } $_SESSION['last_page'] = $_SERVER['PHP_SELF']; ?> include('sql_file_with_login_info'); //$sqluser, $sqlpw, $mydb are defined in this file. $conn = new mysqli('localhost', $sqluser, $sqlpw, $mydb); if($conn->connect_error) { die("Connection Failed: ".$conn->connect_error); //If errored. } $query = "SELECT * FROM table"; //All queries go here, flip the paper for examples. $result = $conn->query($query); if($result->num_rows > 0) { //if $result has any data in the array. while($row = $result->fetch_assoc()) { echo $row['table_column'] } //creates $conn object to make a SQL connection //creates $result object array with $query data. //gets current page file name //sets the global session variable to the current page, so when switching pages you can determine the last page. NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE <?php if($_POST['inputname'] { //if the POST global variable exists. $user = $_POST['inputname']; //assign POST variable to variable echo "Hello ".$user.", Welcome to this page!"; }else{ ?> //suspend PHP, for easier HTML form creation //need a submit button to reload the page <?php } //this is required to end the IF..ELSE loop prior to the form HTML ?> //action should be a PHP page //variable name for POST['inputname'] $_SESSION['custom_attribute'] = global session variable. $_POST['send_to_server'] = incoming submitted form data. $_GET['get_from_server'] = check for variable in URL Example of $_GET www.server.com/index.php?variable=value if($_GET['variable'] { echo $_GET['variable']; } session_destroy(); //deletes all session variables LOOPS while( condition is true, or variable exists ) { //perform actions until condition false } for ($i = 1; $i <= 10; $i++) { //perfom loop 10 times } 3 NORMAL FORM //all take requirements from previous 1 - data need to be economy, smallest format 2 - every non-primary attribute needs to be dependent on the key (functional dependency) 3 - transitivity - every value is non-transitive or dependent on a super key. BNCF "Boyce-Codd Normal Form" or 3.5NF - slightly stronger and fixes anomalies with 3NF MVC - "Model" - "View" - "Controller" -SQL is the Model. -HTML is the View. -PHP is the Controller. //put your own name on your test. UML ER books authors customersbranches CheckoutCarry Visit Wrote title date isbn first last bday locname id (1,0) one to many (0,1) many to one (1,1) one to one RELATIONSHIPS Author id INT First VARCHAR Last VARCHAR bday DATE PRIMARY Wrote author_id book_id Author.id Book.id Book id INT title VARCHAR isbn INT pub DATE PRIMARY Customer id INT name VARCHAR PRIMARY Borrow book_id customer_id Customer.id Book.id

2 SQL Final Exam Guide create table Movie ( mID int PRIMARY KEY, title VARCHAR(200), year int, director VARCHAR(200), UNIQUE (title,year) ); create table Reviewer ( rID int PRIMARY KEY, name VARCHAR(200), ); create table Rating ( rID int, mID int, stars int NOT NULL, ratingDate date, UNIQUE(rID,mID,ratingDate), FOREIGN KEY(rID) REFERENCES Reviewer(rID) ON UPDATE CASCADE ON DELETE SET NULL, FOREIGN KEY(mID) REFERENCES Movie(mID) ON DELETE CASCADE ); //put your own name on your test. MOST COMMON type of join is INNER JOIN, returns all rows from multiple tables where the join condition is met. EX. SELECT o.OrderID, o.OrderID, c.CustomerName FROM Orders o INNER JOIN Customers c ON o.CustomerID = c.CustomerID; REPLACE INNER JOIN WITH FOR SPECIFIC JOIN FEATURES. LEFT JOIN - returns all rows from left table, matching rows in the right table. RIGHT JOIN - returns all rows from right table, matching rows in the left table. FULL OUTER JOIN - returns all rows from both tables. EX. SELECT e.EmployeeID, o.OrdersID FROM Employees e LEFT JOIN Orders o ON e.EmployeeID = o.EmployeeID WHERE e.EmployeeID > 8 ORDER BY e.EmployeeID DESC; //this returns all employees with an ID greater than 8 and all their ORDER IDs from the Orders table SELECT * FROM Products; SELECT SUM(Quantity) AS "Quantity of Sum" FROM OrderDetails; SELECT DISTINCT ProductID FROM OrderDetails WHERE ProductID GROUP BY ProductID; SELECT DISTINCT CustomerName,Country FROM Customers WHERE Country != "USA"; SELECT DISTINCT CurstomerName, Address FROM Customers WHERE Address LIKE("%PO%"); SELECT CategoryID, max(Price) AS "Max Price", min(Price) AS "Min Price" FROM Products WHERE CategoryID GROUP BY CategoryID; SELECT ProductName, FROM Products WHERE CategoryID = (SELECT CategoryID FROM Categories WHERE CategoryName = "Seafood"); SELECT ProductID FROM OrderDetails WHERE OrderID IN (SELECT OrderID FROM Orders WHERE ShipperID = 3) GROUP BY ProductID); To speed up databases there is an optimizer built into databases, also you can use INDEX keys in the database. UPDATE Suppliers SET Country = "United Kingdom" WHERE Country = "UK";


Download ppt "Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE <?php session_start(); //need this before declaring a session global. echo " You."

Similar presentations


Ads by Google