Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Code example 4-1 The starting code for the index.php file which is the first pag

ID: 3656174 • Letter: C

Question

Code example 4-1 The starting code for the index.php file which is the first page of an application <?php require 'database.php'; $category_id = $_GET['category_id']; if (!isset($category_id)) { $category_id = 1; } // Routine 1 $query = "SELECT * FROM categories WHERE categoryID = $category_id"; $category = $db->query($query); $category = $category->fetch(); $category_name = $category['categoryName']; // Routine 2 $query = "SELECT * FROM products WHERE categoryID = $category_id ORDER BY productID"; $products = $db->query($query); ?> (Refer to code example 4-1) The first statement in this example gets and runs a file named database.php. What must this code do for the rest of the statements in this example to work? Answer a. Create a PDO object named $db that connects to the right database b. Create a PDO object named $db-> that connects to the right database c. Create a PDOStatement object named $db-> that connects to the right database d. Create a PDOStatement object named $db that connects to the right database

Explanation / Answer

a. Create a PDO object named $db that connects to the right database note: usually, we do something like this $db = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password); $db->query('some_query_statement'); hope it help u :D