Question

php 1A)connect to the database using the PDO class (you should be able to connect with...

php

1A)connect to the database using the PDO class (you should be able to connect with the username "root" and an empty password)

1C) select all the product names and their list prices, and print them out in a neat HTML table.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<?php


$dbHandle = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$dbHandle->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbHandle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
function get_all($dbHandle) {
$sql = "SELECT product_name and price FROM product_table";
$stmt = $dbHandle->prepare($sql);
$stmt->execute();
$res= $stmt->setFetchMode(PDO::FETCH_ASSOC);
$html_table = '<table border="1" cellspacing="0" cellpadding="2"><tr>';
$nr_col = 2;   
foreach($res AS $key=>$val) {
$html_table .= '<td>' .$key. ' - '. $val. '</td>';   
$i++;
$col_to_add = $i % $nr_col;
if($col_to_add == 0) { $html_table .= '</tr><tr>'; }
}}
get_all($dbHandle);

Add a comment
Know the answer?
Add Answer to:
php 1A)connect to the database using the PDO class (you should be able to connect with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PHP Programming 1a) Create an HTML form to request for email, firstname and lastname, and password....

    PHP Programming 1a) Create an HTML form to request for email, firstname and lastname, and password. A submit button should be available to update a user table in a MySQL database. Name this module login.html. 1b) Create a second HTML form that will be link from the login.html if the user wants to register for the first time. The second form is named register.html. 1c) Create PHP modules to handle the login form and the register form. They should be...

  • 1. Write the php statements to connect to MySQL server and select the database named personnel....

    1. Write the php statements to connect to MySQL server and select the database named personnel. The database personnel is located at localhost server. The user id and password to log on to the server are finalexam and thePassword respectively. 2. Using the above connection, write the php statements to retrieve the name and the email fields from all records of the users table ( 'SELECT name, email FROM users') and display them one record per line.

  • MySQL 8 Create a PHP program that will read in each table of the database you...

    MySQL 8 Create a PHP program that will read in each table of the database you created in Assignment 8 and display the values into a good looking table. When I run it, I'm having this error " Parse error: syntax error, unexpected '$dbName' (T_VARIABLE) in C:\xampp\htdocs\assignment9\includes\dbh.inc.php on line 6' Here is my index.php <?php    include_once 'includes/dbh.inc.php'; ?> <!DOCTYPE html> <html> <head>    <title></title> </head> <body> <?php    $sql = "SELECT * FROM comic_book.books;";    $result = mysqli_query($conn, $sql);...

  • Create web pages for your database using PHP. You should have one page that will return...

    Create web pages for your database using PHP. You should have one page that will return all the information from the database. You should create additional pages that will allow you to do various queries of your database. You should be able to retrieve and insert data; also include functionality to delete data from your database. Create an html form that will allow you to enter in new information for the database. The information should be handled by a PHP...

  • PHP PDO lab Reorganize the code (refactor), write a separate class that implements the interface StudentInterface...

    PHP PDO lab Reorganize the code (refactor), write a separate class that implements the interface StudentInterface and use the methods in this class to show the list of students and details of a student. - All SQL queries are moved into the methods defined in the interface and the methods return data back to the calling program. - Use prepared statements for queries that take one or more input parameters. interface StudentInterface {    public function visAlle() : array;   ...

  • You need to implement a web application that is split in three parts, namely, Webpage, PHP...

    You need to implement a web application that is split in three parts, namely, Webpage, PHP and MySQL. Each of them will be used accordingly to solve a simple problem described below. Remember to implement the logic in the most secure way of your knowledge. PHP Implement a PHP function that reads in input a string from the user and store it in a table (e.g., in a field called "Content Name"). The function should be able to read the...

  • You need to implement a web application that is split in three parts, namely, Webpage, PHP and My...

    You need to implement a web application that is split in three parts, namely, Webpage, PHP and MySQL. Each of them will be used accordingly to solve a simple problem described below. Remember to implement the logic in the most secure way of your knowledge. PHP Implement a PHP function that reads in input a string from the user and store it in a table (e.g., in a field called "Content Name"). The function should be able to read the...

  • Using MySQL and PHP keep it simple This assignment you will be making a form that...

    Using MySQL and PHP keep it simple This assignment you will be making a form that will do one of three things in a database -          It will add a record -          It will update a record -          It will search for a record Your database will contain a table for keeping a record of all your friends and family and should contain: First name Last name Phone number Address City State Zip Birthdate Username Password The sex of the...

  • This assignment require using different Bootstrap classes for styling. I have used some "class=" (bootstrap) in...

    This assignment require using different Bootstrap classes for styling. I have used some "class=" (bootstrap) in code, but they don't work. In HTML, we need to add < link > to display bootstrap, but I don't know what to do in PHP. <?php $servername = "fdb29.awardspace.net"; $username = "3515976_assignment9"; $password = "Becky516."; $database = "3515976_assignment9"; $port = "3306"; // Create connection $dbconn = mysqli_connect($servername, $username, $password, $database, $port); if($dbconn){ }else{ die("Connection Failed: ".mysqli_connect_error()); } $myQuery = "SELECT p_name, p_desc, p_img,...

  • I need help showing the first column of the table to show up exactly with the...

    I need help showing the first column of the table to show up exactly with the mysql table into the php page. Is there a way to fix it ? So I created a php form where the user enters the information. sand.truman.edu/~jyl6557/assignment5/hw5-dataentry.php . it asks for name, hometown, gender(only male and female) and status (freshman, sophmore, junior, senior). once it checks and passes through those tests, it would say added successfully and then show the links to add another...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT