Internet Programming Midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What will the following script output? <?php $temp=explode("**", "A**sentence**with**asterisks"); print_r($temp); ?>

$temp is a four-element array containing "A", "sentence", "with", "asterisks"

What function counts elements in an array?

count

Which of the following functions reads the entire contents of a file? fgets() file_get_contents() fread() readfile()

file_get_contents()

How can you incorporate one PHP file within another?

To incorporate one file within another, you can use the include or require directives, or their safer variants, include_once and require_once.

How can you set PHP's internal pointer into an array back to the first element of the array?

To reset PHP's internal pointer into an array back to the first element, call the reset function. (end of chapter 6)

What is the output of the following PHP code? <?php $a="1000"; $b="+1000"; if($a==$b) echo "1"; else echo "2"; ?>

1

Given the following PHP script: $p2=array('first name'=>"Mary", 'last name'=>"Fox", 'phone'=>"(407)456-0101"); Which PHP statement correctly prints the value of last name, Fox?

echo $p2['lastname'];

Which form ensures that the columns containing repeated data should be moved to their own tables?

2NF

What will the following script output? <?php $array=array(1, 2, 3, 5, 8, 13, 21, 34, 55); $sum=0; for($i=0;$i<5; $i++){ $sum+=$array[$array[$i]]; } echo $sum; ?>

78

What negative effects can happen if you do not close the objects created by mysqli methods?

If you neglect to properly close objects created with mysqli methods, your programs carry the risk of running out of memory, especially on high-traffic websites. If there's a program flow logic error in your code, closing objects will also ensure you won't accidentally access old results.

What does the predefined constant _FILE_ mean? It contains the full path of the file. It contains the filename of the file. It contains the full path and the filename of the file. None of the above.

It contains the full path and the filename of the file.

Both SELECT DISTINCT and GROUP BY cause the display to show only one output row for each value in a column, even if multiple rows contain that value. What are the main differences between SELECT DISTINCT and GROUP BY?

SELECT DISTINCT essentially affects only the display, choosing a single row and eliminating all the duplicates. GROUP BY does not eliminate rows, but combines all the rows that have the same value in the column. Therefore, GROUP BY is useful for performing an operation such as COUNT on groups of rows. SELECT DISTINCT is not useful for that purpose.

In order to show multiple entries only once when they contain the same data, we might use the command

SELECT DISTINCT filename FROM tablename WHERE...

Write an SQL statement to get the total sale price for large size pizzas(assume that prices in table menu are for large ones) on the date 2019-02-03. (tip: Use join operation, SUM() function. In order to get price for each type of pizza, join orders and pizza tables: orders.pizzaID=pizza.pizzaID).

SELECT SUM(price*quantity), DATE(orderDate), size FROM orders JOIN menu ON orders.pizzaID=menu.pizzaID WHERE size='L' AND DATE(orderDate)='2019-02-03';

Write an SQL statement to show the total quantity of large size pizzas placed each day. The total quantities are grouped by the sorted date. The results include the total quantity of each day placed and date. (tip: Use SUM() function, GROUP BY Date(orderDate))

SELECT SUM(quantity), DATE(orderDate) FROM orders WHERE size='L' GROUP BY DATE(orderDate) ORDER BY DATE(orderDate);

Write an SQL statement to show the total quantity of each day and the corresponding date. The orders are grouped by orderdate. (tip: Use SUM() function, and GROUP BY DATE(orderdate)).

SELECT SUM(quantity), DATE(orderDate) FROM orders GROUP BY DATE(orderdate);

Write an SQL statement to show the total quantities for each type of pizza sold(Use GROUP BY pizzaId)) . the results include pizzaID, pizzaName, total quantities, and size.

SELECT SUM(quantity), orders.pizzaID, menu.pizzaName, size FROM orders JOIN menu ON orders.pizzaID=menu.pizzaID GROUP BY orders.pizzaID, size;

Write an SQL statement to show total number of each type of pizza sold on 2019-02-03 in the table orders. Namely, the orders are grouped by type of pizza using ascending order. The results include the number of each type of pizza sold, pizzaId, pizzaName, and size. ( Use SUM() function, and join both tables by pizzaID and group by orders.pizzaID).

SELECT SUM(quantity), orders.pizzaID, menu.pizzaName, size FROM orders JOIN menu ON orders.pizzaID=menu.pizzaID WHERE DATE(orderDate)='2019-02-03' GROUP BY orders.pizzaID, size;

Write an SQL statement to show all orders placed in the day 2019-02-03 in the orders table. The results include customerID, quantity, and size, and sorted by customerID. (Tip: use DATE() function to get '2019-02-03'. So, do WHERE DATE(orderdate)='2019-02-03' )

SELECT customerID, quantity, size FROM orders WHERE DATE(orderdate)='2019-02-03' ORDER BY customerID;

(Join operation) Write an SQL statement to show the order placed by customerID, 123 on the date 2019-02-01. The results include orderID, pizzaName, size and quantity (in order to get pizzaname for a pizzaId, you need to join pizza and orders table, so add one more condition: orders.pizzaID=pizza.pizzaID in WHERE clause ).

SELECT orderID, menu.pizzaName, size, quantity FROM orders JOIN menu ON orders.pizzaID =menu.pizzaID WHERE customerID=123 AND DATE(orderdate)='2019-02-01';

Write an SQL statement to show the order placed by customerID, 156 on the date 2019-02-03. The results include orderID, pizzaID, size and quantity (Tip: use DATE() function to get '2019-02-03', Use two conditions customerId=156 and Date(orderdate)='2019-02-03';).

SELECT orderID, pizzaID, size, quantity FROM orders WHERE customerID = 156 AND DATE(orderdate)='2019-02-03';

Write an SQL statement to show all orders placed by customerID, 123. The results include pizzaID, quantity, size, and orderdate.

SELECT pizzaID, quantity, size, orderDate FROM orders WHERE customerID = 123;

Write an SQL statement to show all pizza where the prices are less than $10. The results include pizza name, price, and description.

SELECT pizzaName, price, topping FROM menu WHERE price < 10;

What is the meaning of scope in PHP?

Scope refers to which parts of a program can access a variable. For example, a variable of global scope can be accessed by all parts of a PHP program.

What is the main benefit of the array keyword?

The main benefit of the array keyword is that it enables you to assign several values at a time to an array without repeating the array name.

What is the purpose of semicolons in MySQL queries?

The semicolon in MySQL separates or ends commands. If you forget to enter it, MySQL will prompt and wait for you to enter it.

What tag is used to invoke PHP to start interpreting PHP code? And what is the short form of the tag?

The tag used is <?php ... ?>

What is the difference between ++$j and $j++?

There is no difference between ++$j and $j++ unless the value of $j is being tested, assigned to another variable, or passed as a parameter to a function. In such cases, ++$j increments $j before the test or other operation is performed, whereas $j++ performs the operation and then increments $j.

How do you convert one variable type to another? A string to a number?

To convert one variable type to another, reference it and PHP will automatically convert it for you.

How would you create a Unix timestamp for 7:11 a.m. on May 2, 2016?

To create a Unix timestamp for 7:11 a.m. on May 2nd, 2016, you could use the following command: $timestamp = mtkime(7, 11, 0, 5, 2, 2016);

How can you create a database with a many-to-many relationship?

To create a database with a many-to-many relationship, you create an intermediary table contains keys from two other tables. The other tables can then reference each other via the third.

How can you create a multidimensional array?

To create a multidimensional array, you need to assign additional arrays to elements of the main array.

How do you create a new object in PHP?

To create a new object in PHP, use the new keyword like this: $object = new Class;

What syntax would you use to create a subclass from an existing one?

To create a subclass, use the extends keyword with syntax such as this: class Subbclass extends Parentclass

How would you create a new MySQL user on the local host called newsier with a password of new pass and with access to everything in the database newdatabase?

To create this new user, use the GRANT command like this: GRANT PRIVILEGES ON newdatabase.* TO 'newuser'@'localhost' IDENTIFIED BY 'newpassword';

How can you determine the number of rows returned by a mysqli query?

To determine the number of rows returned by a mysqli query, use the num_rows property of the result object.

How can you ensure that an input is completed before a form gets submitted?

To ensure that a form is not submitted with missing data, you can apply the required attribute to essential inputs.

Which mysqli method can be used to properly escape user input to prevent code injection?

To escape special characters in strings, you can call the real_escape_string method of a mysqli connection object, passing the the string to be escaped. Of course, for security, using prepared statements will serve you best.

What commands initiate and end a MySQL transaction?

To initiate a MySQL transaction, use the BEGIN or START TRANSACTION command. To terminate a transaction and cancel all actions, issue a ROLLBACK command. To terminate a transaction and commit all actions, issue a COMMIT command.

Using the SELECT...WHERE construct, how would you return only rows containing the word Langhorne in the author column of the classics table?

To return only those rows containing the word Langhorne somewhere in the column author of the table classics, use a command such as this: SELECT * FROM classics WHERE author LIKE "%Langhorne%";

How can you make a table satisfy the Second Normal Form?

To satisfy Second Normal Form, columns whose data repeats across multiple rows should be removed to their own tables.

Which command would you use to view the available databases or tables?

To see the available databases, type SHOW databases. To see tables within a database that you are using, type SHOW tables. (These commands are case insensitive).

To send the output from printf to a variable instead of to a browser, what alternative function would you use?

To send the output from printf to a variable instead of to a browser, you would use sprintf instead.

What printf statement could be used to take the input string "Happy Birthday" and output the string "**Happy"?

To take the input string "Happy Birthday" and output the string "**Happy", you could use a printf statement such as this: printf("%'*7.5s", "Happy Birthday");

How can you view the structure of a table?

To view the structure of a table, type DESCRIBE tablename.

What is the difference between accessing a variable by name and by reference?

When you reference a variable by name, such as by assigning its value to another variable or by passing its value to a function, its value is copied. The original does not change when the copy is changed. But if you reference a variable, only a pointer (or reference) to its value is used, so that a single value is referenced by more than one name. Changing the value of the reference will change the original as well.

How can you make a variable accessible to all parts of a PHP program?

You can make a variable accessible to all parts of a PHP program by declaring it as global.

How can you submit a group of selections from a web form using a single field name?

You can submit a group of selections from a web form using a single field name by using an array name with square brackets, such as choices[], instead of a regular field name. Each value is then placed into the array, whose length will be the number of elements submitted.

How can you create a multiline echo or assignment?

You can use multiple lines within quotation marks or the <<<_END..._END; construct to create a multiline echo or assignment. In the latter case, the closing tag must be on a line by itself with nothing before or after it.

How can you determine the number of elements in an array?

You can use the count function to count the number of elements in the array.

Can you redefine a constant?

You cannot redefine constants because, by definition, once defined they retain their value until the program terminates.

You must put ___ before PHP variables. % # $ Letter

$

PHP statement ends with: ; . nothing All of them are OK

;

What can a variable store?

A variable holds a value that can be a string, a number, or other data.

Which character must be placed at the end of every PHP statement?

All PHP statements must end with a semicolon (;)

How many values can a function return?

By default, a function can return a single value. But by initializing arrays, references, and global variables, it can return any number of values.

What do you put in a column to tie together two tables that contain items having a one-to-many relationship?

In a one-to-many relationship, the primary key from the table on the "one" side must be added as a separate column (a foreign key) to the table on the "many" side.

The difference between include_once and require_once statement is mainly

PHP will continue its execution even if the file is not found for include_once, while PHP will stop its execution for require_once if the file is not found.

Which PHP super global variable holds the details on uploaded files?

The PHP super global associative array $_FILES contains the details about uploaded files.

You can submit form data using either the POST or the GET method. Which associative arrays are used to pass this data to PHP?

The associative arrays used to pass submitted form data to PHP are $_GET for the GET method and $_POST for the POST method.

What is the term for the process of removing duplicate data and optimizing tables?

The process of removing duplicate data and optimizing tables is called normalization.

What is the purpose of a MySQL index?

The purpose of a MySQL index is to substantially decrease database access times by adding some metadata to the table about one or more key columns, which can then be quickly searched to locate rows within a table.

What does the word relationship mean in reference to a relational database?

The term relationship refers to the connection between two pieces of data that have some association, such as a book and its author, or a book and the customer who bought the book. A relational database such as MySQL specializes in storing and retrieving such relations.

What command would you use to back up the database publications to a file called publications.sql?

To back up the database publications to a file called publications.sql, you would use a command such as: mysqldump -u user -ppassword publications > publications.sql

How can you submit a form field without displaying it in the browser?

To submit a form field without the user seeing it, place it in a hidden field using the attribute type="hidden".

How do you submit a query to MySQL using mysqli?

To submit a query using mysqli, ensure you have first created a connection object to a database and then call its query method, passing the query string.

What is the main benefit of using a function?

Using functions avoids the need to copy or rewrite similar code sections many times over by combining sets of statements so that they can be called by a simple name.

What is the result of combining a string with a number?

When you combine a string with a number, the result is another string.

What is the output of the following PHP code? <?php $n="WILLIAM"; echo fix_names($n); function fix_names(&$n1) { $n1=ucfirst(strtolower($n1)); } echo "$n"; ?>

William

With symbol is used to preface every all PHP variables?

With the exception of constants, all PHP variables must begin with $.

Which HTML tag is used to encapsulate a form element and supporting text or graphics, making the entire unit selectable with a mouse-click?

You can encapsulate a form element and supporting text or graphics, making the entire unit selectable with a mouse click, by using the <label> and </label> tags.

What form attribute can be used to help users complete input fields?

You can help users complete fields with data they may have submitted elsewhere by using the autocomplete attribute, which prompts the user with possible values.

What is the output of the following php code? <>php echo ?a:[?.(20>9).?]<br>?; echo ?b:[?.(5==9).?]<br>?;

a:[1] b:[]

You can create ___ to conduct a fast search.

an index

Assume you would like to sort an array in ascending order by value while preserving key associations. Which PHP sorting function would you use?

asort()

In order to connect to MySQL database, you use mysqlConnect() mysql_query() mysql_connect() None of the above are correct

mysql_connect()

Which PHP method is used to build and execute a query?

mysql_query()

What function is used to prevent SQL injection?

mysql_real_escape_string()

What benefit does a FULLTEXT index provide?

A FULLTEXT index enables natural-language queries to find keywords, wherever they are in the FULLTEXT column(s), in much the same way as using a search engine.

What is the difference between a numeric and an associative array?

A numeric array can be indexed numerically using numbers or numeric variables. An associative array uses alphanumeric identifiers to index elements.

Which data type causes MySQL to set a unique value for a column in ever row?

AUTO_INCREMENT

How can you cause an object to be initialized when you create it?

To cause an object to be initialized when you create it, you can call a piece of initializing code by creating a constructor method called __construct within the class, and place your code there.

Which of the following SQL commands can be used to modify existing records in a database table? MODIFY UPDATE CHANGE NEW

UPDATE

Write an SQL statement to update the price to 13.99 for the type of pizza, "work" in pizza table.

UPDATE menu SET price = 13.99 WHERE pizzaName = ' Works';

How can you retrieve a string containing an error message when a mysqli error occurs?

When a mysqli error occurs, the error property of the connection object contains the error message. If the error was in connecting to the database, the connect_error property will contain the error message.

Which file access mode would you use with open to open a file in write and read mode, with the file truncated and the file pointer at the start?

You would use the w+ file access mode with open to open a file in write and read mode, with the file truncated and the file pointer at the start.

PHP variables are: case sensitive case insensitive start with # end with $

case sensitive

Which function prevents the same file from being included more than once in a page? include() include_once() require() All of them are correct.

include_once()

Superglobal variables can be accesses everywhere in your whole web site. An example of the superglobal variable is: $_COOKIE _COOKIE $COOKIE None of them are correct

$_COOKIE

In order to get the id generated automatically for an auto-increment column from the previous INSERT query, you use

$insertID=mysql_insert_id();

What is the correct way to class a member function of the Class User? $object.get_password(); $object->get_password(); $object->get_password; None are correct

$object->get_password();

In order to delete a record with a particular isbn value stored in the variable $isbn in PHP, you use

$query="DELETE FROM classics WHERE isbn='$isbn'";

In order to add a user name "Mary" and password "Mary111" into the table user in PHP, the variable $query should be:

$query="INSERT INTO user VALUES('Mary', 'Mary111');

To update a record with a particular author name stored in the variable $author in PHP, you use

$query="UPDATE classics SET author='$author'";

What is the difference between $variable = 1 and $variable == 1?

$variable = 1 is an assignment statements, whereas the == in $variable == 1 is a comparison operator.

How is an object different from a function?

A function is a set of statements referenced by a name that can receive and return values. An object may contain zero or many functions (which are then called methods) as well as variables (which are called properties), all combined in a single unit.

What is a stopword?

A stopword is a word that is so common that it is considered not worth including in a FULLTEXT index or using in searches. However, it is included in searches when it is part of a larger string bounded by double quotes.

What is the difference between foreach and each?

Both the each function and the foreach... as loop construct return elements from an array; both start at the beginning and increment a pointer to make sure the next element is returned by the following call or iteration, and both return FALSE when the end of the array is reached. The difference is that the each function returns a single element, so it is usually wrapped in a loop. The foreach... as construct is already a loop, executing repeatedly until the array is exhausted or you explicitly break out of the loop.

Which of the following is not an SQL aggregate function? AVG SUM MIN CURRENT_DATE()

CURRENT_DATE()

clone operator will

Create a new instance of a class and copy the property values from the original instance

Why is it a good idea to explicitly declare properties within a class?

Explicitly declaring properties within a class is unnecessary, as they will be implicitly declared upon first use. But it is considered good practice as it helps with code readability and debugging, and is especially useful to other people who may have to maintain your code.

Are the operators and and && interchangeable?

Generally, the operators && and and are interchangeable except where precedence is important, in which case && has a high precedence, while and has a low one.

INSERT the following record into the pizza table using SQL: 6, 'veggie lover', 10.99, 'veggies, and cheese', 'work.jpg'

INSERT INTO menu (pizzaID, pizzaName, price, topping, imgName) VALUES (6, 'veggie lover', 10.99, 'veggies, and cheese', 'work.jpg');

If you generate data within a function, what are a couple of ways to convert the data to the rest of the program?

If you generate data within a function, you can convey the data to the rest of the program by returning a value or modifying a global variable.

Which of the following tag styles in preferred in HTML5: <hr> or <hr />?

In HTML5, you can use either XHTML style of tag (such as <hr />) or the standard HTML4 style (such as <hr>). It's entirely up to you or your company's coding style.

Why do you suppose that an underscore is allowed in variable names ($current_user), whereas hyphens are not ($current-user)?

In PHP, the hyphen is reserved for the subtraction, decrement, and negation operators

What is the PHP command for deleting the file file.txt?

The PHP command for deleting the file file.txt is as follows: unlink('file.txt');

Which PHP function enables the running of system commands?

The PHP exec function enables the running of system commands.

Which PHP function is used to read in an entire file in one go, even from across the web?

The PHP function file_get_contents is used to read in an entire file in one go. It will also read a file from across the internet if provided with a URL.

Which printf conversion specifier would you use to display a floating-point number?

The conversion specifier you would use to display a floating-point number is %f.

What is the difference between a text box and a text area?

The difference between a text box and a text area is that although they both accept text for form input, a text box is a single line, whereas a text area can be multiple lines and include word wrapping.

What is the difference between the echo and print commands?

The echo and print commands are similar in that they are both constructs, except that print behaves like a PHP function and takes a single argument, while echo can take multiple arguments.

What is the purpose of functions?

The purpose of functions is to separate discrete sections of code into their own self-contained sections that can be referenced by a single function name.

What is the purpose of the explode function?

The purpose of the explode function is to extract sections from a string that are separated by an identifier, such as extracting words separated by spaces within a sentence.

What output will the PHP statement produce? printf("The result is $10.2f\n", 123.43/10);

The results is $ 12.34

What are the three rules of the First Normal Form?

The three rules of First Normal Form are as follows: - There should be no repeating columns containing the same kind of data. - All columns should contain a single value. - There should be a primary key to uniquely identify each row.

What is the difference between single quotation marked strings and double quotation marked strings? Suppose the whole string $s contains a variable $s1.

The variable $s1 will be evaluated if the string $s is marked with double quotation.

What features does MySQL provide to enable you to examine how a query will work in detail?

To examine how a query will work in detail, you can use the EXPLAIN command.

How do you connect to a MySQL database using mysqli?

To connect to a MySQL database with mysqli, call the mysqli method, passing the hostname, username, password, and database. A connection object will be returned on success.

Which PHP function converts HTML into a format that can be displayed but will not be interpreted as HTML by a browser?

To convert HTML into a format that can be displayed but will not be interpreted as HTML by a browser, use the PHP htmlentities function.

How can you retrieve a particular row of data from a set of mysqli results?

To retrieve a specific row from a set of mysqli results, call the data_seek method of the result object, passing it the row numbers (starting from 0); then call fetch_array or another retrieval method to obtain the required data. This is not required if fetching all results.

What needs to be defined in two tables to make it possible for you to join them?

When you're joining two tables together they must share at least one column.

What are the two types of comment tags?

You can use // for a single-line comment or /*...*/ to span multiple lines.

How do you escape a quotation mark?

You can use \' or \" to escape either a single or double quote.

PHP function names are: case sensitive case insensitive start with # start with $

case insensitive

Which of the following PHP statements produce the data in the format "Sunday, January 4th, 2015"? echo date("l, M ds, Y", time()); echo date("l, F ds, Y", time()); echo date ("l, F js, Y", time()); None of the above are correct.

echo date("l, F js, Y", time());


Kaugnay na mga set ng pag-aaral

Chapter 11 Quiz **one is wrong***

View Set

Digital forensic Quiz assessment

View Set

020301hA - Survey Equipment - Part A

View Set

Quiz 5 Information Security Fundamentals

View Set

RELIGION CTT Ch. 9 The Age of the Imperial Church

View Set

the largest quizlet set ever!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

View Set

Project Management - The Managerial Process 7E - Unit 1

View Set

Module 1 health promotions for advance practice nurses

View Set