PHP Midterm

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

PHP variable names start with which symbol? ! $ & #

$

What is the HTTP response code for a page that has been permanently moved? 301 201 404 302

301

A client can dictate what type of response the REST API sends based on ____________________. Accept Parameters Connection Type CORS Parameters Database Type

Accept Parameters

When we built a simple web server using only Node.js (not Express!), what did we NOT address with the server? Content-Type CORS Request Methods Port Numbers

CORS

By default, PHP is a strictly typed language. True False

False

Parameters and Arguments mean the same thing in reference to PHP functions. True False

False

Select the answer that displays the HTTP methods that will not trigger a CORS preflight OPTIONS request (with some exceptions). GET, POST, PATCH GET, HEAD, POST GET, PUT, DELETE GET, POST, PUT

GET, HEAD, POST

MVC is an acronym for __________________________________. Model-View-Constructor Model-View-Container Model-View-Controller Model-View-Class

Model-View-Controller

CRUD stands for Create, Read, Update and Delete. HTTP Methods (aka Verbs) can be matched with these. Select the exact order of HTTP Methods that matches the order of the CRUD acronym. POST, GET, PUT, DELETE PUT, POST, GET, DELETE GET, PUT, POST, DELETE GET, POST, PUT, DELETE

POST, GET, PUT, DELETE

A 201 status code is typically sent in response to what type of client requests? PUT and PATCH PUT and POST GET and POST PUT and DELETE

PUT and POST

PHP is currently utilized in a majority of websites. True False

True

When you create PHP constant values, you can indicate if the constant is case-sensitive. True False

True

In Express, what request method do we use to check if the client request supports a specific content-type? supports content-type accepts receives

accepts

MVC is a _________________ pattern. code design file PHP

design

res.end( {data: 'Hello World!'} ); There is an issue with the above response. Choose the correct version of this line of code. res.end(JSON.parse({data: 'Hello World!'})); res.end({data: 'Hello World!'}).json(); res.end(JSON({ data: 'Hello World!'})); res.end(JSON.stringify({data: 'Hello World!'}));

res.end(JSON.stringify({data: 'Hello World!'}));

Dependency injection is a _________________ in which an object receives other __________________ that it depends on, called dependencies. method, properties method, objects technique, objects technique, classes

technique, objects

const myValue = 42; const myFunction = (num) => { return num > 50 ? 'big number' : num > 40 ? 'medium number' : num > 30 ? 'average number' : 'small number'; } myFunction(myValue); What is the returned value from the above function call? big number' 'small number' 'medium number' 'average number'

'medium number'

$x = 10; $y = "10"; Select the comparison that will evaluate to true. $x != $y $x == $y $x === $y $x <=> $y

$x == $y

$grades = array("A"=>90, "B"=>80, "C"=>70); echo "To achieve an A grade, you must score {$grades[0]} or above."; What is wrong with the code above? $grades[0] should be replaced with $grades["0"] $grades[0] should be replaced with $grades["A"] $grades[0] should be replaced with $grades[90] $grades[0] should be replaced with $grades["90"]

$grades[0] should be replaced with $grades["A"]

Which code supports a LIKE clause in the SQL statement that searches within the city column data? (not only at the beginning or the end of the column data) $query = 'SELECT * FROM city WHERE Name LIKE %:city% ORDER BY Population DESC'; $statement->bindValue(':city', $city); $query = 'SELECT * FROM city WHERE Name LIKE :city ORDER BY Population DESC'; $statement->bindValue(':city', "%" . $city . "%"); $query = 'SELECT * FROM city WHERE Name LIKE %:city ORDER BY Population DESC'; $statement->bindValue(':city', $city); $query = 'SELECT * FROM city WHERE Name LIKE :city ORDER BY Population DESC'; $statement->bindValue(':city', "%+$city+%");

$query = 'SELECT * FROM city WHERE Name LIKE :city ORDER BY Population DESC'; $statement->bindValue(':city', "%" . $city . "%");

Like JavaScript, you can concatenate PHP strings with the + operator True False

False

PHP code is executed in the browser. True False

False

function addCoffee(&$word) { $word = $word . "coffee"; } $myWord = "Good"; addCoffee($myWord); echo $myWord; What will the output be? Good coffee Good Error! There's an ampersand in the parameter. Goodcoffee

Goodcoffee

You have a database with a blogs table. The blogs table contains multiple records with several columns of data. The id column is set to auto-increment and is also the primary key. Which SQL statement will properly insert a new record in the blogs table? INSERT INTO blogs id="1", post="My cool post.", author="Jane Doe" INSERT INTO blogs (id, post, author) VALUES (1, "My cool post.", "Jane Doe") INSERT INTO blogs post="My cool post.", author="Jane Doe" INSERT INTO blogs (post, author) VALUES ("My cool post.", "Jane Doe")

INSERT INTO blogs (post, author) VALUES ("My cool post.", "Jane Doe")

Each schema maps to a ________________ and defines the shape of the documents within it. API endpoint SQL table MongoDB collection Express route

MongoDB collection

NPM is an acronym for _______________________. Node Package Master No Pringles Mister! Node Packages Mostly Node Package Manager

Node Package Manager

When a REST API accepts JSON requests from clients, what HTTP method MUST be configured in the REST API for browsers to allow the requests? POST GET CONNECT OPTIONS

OPTIONS

Mongoose is an _______________________ for MongoDB and Node.js. Object-Oriented Framework Object Data Modeling Library Object Structure Template Object Query Language

Object Data Modeling Library

PHP variable names are case-sensitive. True False

True

In contrast to a server-side programming language like PHP, Node.js handles tasks _______________________. asynchronously declaratively synchronously procedurally

asynchronously

When constructing a Switch statement, every case should end with a _________________ until you reach the default code to be executed. conditional exception break continue

break

Node.js is designed to __________________________. build scalable browser applications be a single source for 3rd party packages replace Vanilla JavaScript within 5 years build scalable network applications

build scalable network applications

If I provide the following: const Car = mongoose.model('Car', schema);What collection will Mongoose look for in the database? Look closely! car Cars cars Car

cars

const myValue = 42; const myFunction = (num) => { return num > 50 ? 'big number' : num > 40 ? 'medium number' : num > 30 ? 'average number' : 'small number';} What type of conditional statement is used in myFunction? chained ternary statement switch statement object lookup if / else if / else

chained ternary statement

We can handle multiple HTTP methods for the same route through the use of method ________________. callbacks values cors chaining

chaining

Object Oriented Programming uses ______________ as blueprints for creating objects. classes properties MVC methods

classes

With Node.js, connections are handled _________________________. concurrently in reverse order one at a time Node.js doesn't handle connections

concurrently

In order to create, fire, and listen for events in Node.js, we must import a core module. Select the correct import statement. const emitter = require(new EventEmitter()) var events = require('eventlistener') const EventEmitter = require('eventEmitter') const EventEmitter = require('events')

const EventEmitter = require('events')

With the MVC design pattern, we use _________________ files to store most methods that will be called in our Express routes. model view middleware controller

controller

const server = http._____________((req, res) => { listen createServer server on(server,

createServer

An instance of a model is called a _______________. record query document object

document

Which statement is often used to display output in PHP? printScreen screenPrint echo display

echo

We want our PHP OOP REST API to respond with a JSON success message. To accomplish this, we need to _________________________. echo toJSON(array('message' => 'Success') ) echo json_decode(array('message' => 'Success') ) echo json_encode(array('message' => 'Success') ) $post->toJSON(array('message' => 'Success') )

echo json_encode(array('message' => 'Success') )

When we store passwords outside of our code, they are stored in ________________ so our applications can access and use them. environment variables JSON config.php config arrays

environment variables

Instead of handling all paths in one file, we can implement routes to other directories in Express. Each route has its own file that requires us to import _________________ to handle the routes. express.Path() express.Router() express.Routing() express()

express.Router()

Using Mongoose, documents can be retrieved in several ways. Select the method that does NOT exist to retrieve documents in Mongoose. findById find findOne findMany

findMany

A major advantage of choosing PDO over MySQLi for a database connection is __________________. flexibility. PDO supports 12 different database systems, but MySQLi will only work with MySQL databases. OOP (object oriented programming). PDO supports OOP while MySQLi does not. acroynyms. PDO is easy to remember and type. MySQLi is as easy to type as rEsEaRcH. procedural programming. PDO supports procedural programming while MySQLi does not.

flexibility. PDO supports 12 different database systems, but MySQLi will only work with MySQL databases.

One huge benefit of using MVC is _____________________. that there is only way to implement it correctly - making it easy for all to understand your code. that it reduces the amount of code in both small and large projects. that it creates a separation of concerns. that it only works with OOP.

that it creates a separation of concerns.

The $this keyword refers to _______________________. the current method the current class the current property the current object

the current object

In the following line of code: Person.findOne({ 'name.last': 'Ghost' }, 'name occupation', function (err, person) {...what does 'name occupation' represent? the fields that must match the value 'Ghost' the query fields for the search secondary fields to search if no match is found initially the fields selected from each matching document

the fields selected from each matching document

NPM consists of 3 distinct components. Select the answer that is NOT one of the 3 distinct components. the index the website the command line interface (CLI) the registry

the index

When referring to a REST API, we're referring to __________________. objects the client the part of the server that receives requests and sends responses the server

the part of the server that receives requests and sends responses

It is not safe to push code to a Github repository that contains passwords. Instead, we store passwords for our application's database connection _____________________. on the host server. on the client server. in the browser. in CORS.

on the host server.

What file does npm create in your project to track packages? package.init package.json package.index package.master

package.json

The following code sample is an example of code that could be specifically used with what type of statement? Choose the BEST answer. $stmt->bindParam(':email', $email); MySQL MySQLi select prepared

prepared

To generate a random number in PHP, you should use the __________ function. serialize rand random randNum

rand

The syntax needed to import modules into your Node.js code is similar to PHP. In Node.js, we should use _______________________. require include require_once include_once

require

What type of conditional statement is applied in this function? const myFunction = () => 42 ? 'answer' : 'puzzle'; switch statement if else statement chained ternary statement ternary statement

ternary statement

Which is NOT an access modifier? unprotected public protected private

unprotected

HTML form data may also be referred to as ____________________. JSON data urlencoded data object data key-value pairs

urlencoded data

What method do we use in Express to apply built-in middleware? all use route get

use

If you need to know the data type and value of a PHP variable, you should use the _______________ function. var_dump toString typeof type_of

var_dump

We want our REST API to respond with HTML. Therefore, we need to set the Content-Type header value to __________________________. "html/css" "text/html" "text/plain" "application/html"

"text/html"

In Express, the get method (and other similar methods) have two parameters. Select the answer that presents the correct parameters in the correct order. (callback, path) (path, next) (path, callback) (callback, next)

(path, callback)

What status code should a REST API send to a client application when the API does not provide the type of data requested in the accept parameter? 406 Not Acceptable 403 Forbidden 400 Bad Request 500 Server Error

406 Not Acceptable

When we call the get() method on an Express app in our code like: app.get() What does get represent? A method that accepts all requests and gets the requested files It gets a specific route for all HTTP methods A method that routes HTTP GET requests An object lookup

A method that routes HTTP GET requests

When we see the following code: $post = new Post($db); We know the following to be true: A new post is being created. The Post class requires a database connection to be passed to the constructor. If the Post class has any default values or methods, we can now access them in our code with $post. All new post is being created. The Post class is receiving an optional database connection in the constructor. We must set property values for $post before accessing any $post methods. All $post object values were set before this statement. The new $post values are being sent to the database. A new post is being created. The Post class requires a database connection to be passed to the constructor. We can only access the default values of $post after we set them.

A new post is being created. The Post class requires a database connection to be passed to the constructor. If the Post class has any default values or methods, we can now access them in our code with $post.

From the code below: $stmt->bindParam(':id, $this->id'); We realize the following: A prepared SQL statement is being constructed. The id parameter of the class will hold the value of the id variable. An object is being constructed. The id parameter of the object will hold the value of the id class. An object is being constructed. The id parameter of the class will hold the value of the id variable. A prepared SQL statement is being constructed. The id parameter of the prepared statement will hold the value of the object's id property.

A prepared SQL statement is being constructed.

What does the array in the following code represent? app.get('/chain(.html)?', [one, two, three]); An array of callbacks for the specified route. An array of regular expressions to validate the specified route. An array of routes to redirect the specified route to. An array of values to send as responses to the specified route.

An array of callbacks for the specified route.

Node.js is an asynchronous event-driven JavaScript runtime built on _________________________________. the Chrome server the Chrome API the Chrome browser Chrome's V8 JavaScript engine

Chrome's V8 JavaScript engine

When the server sends data to a client, it must include the _______________ header. Server-State Access-Allow-Origins Content-Type Accept

Content-Type

I am concerned that my PHP form may be easily hacked with XSS. I am going to use the htmlspecialchars() function to prevent this. What does htmlspecialchars() do? Minifies your code. Prevents you from using the super global variable $_SERVER["PHP_SELF"] Converts special characters like < and > to HTML entities. Encrypts your code.

Converts special characters like < and > to HTML entities.

The acronym CORS is short for _______________________. Cross-Origin Resource Sharing Cross-Origin REST State Cross-Origin RESTful Syntax Cross-Origin Resource Submissions

Cross-Origin Resource Sharing

Which SQL statement will delete a record with an id equal to 10 from the blogs table? (and only that record) DELETE FROM blogs WHERE id=10 DELETE id=10 FROM blogs DELETE * FROM blogs SELECT id FROM blogs WHERE id=10 and DELETE

DELETE FROM blogs WHERE id=10

What is the acronym REST an abbreviation for? REpresentational State Transfer REading Stops Tears RElay State Transfer REdux State Transfer

REpresentational State Transfer

You have a database with a blogs table. The blogs table contains multiple records with several columns of data. One of those columns is named id and it is the primary key for the table. Which SQL statement will select the full record with an id equal to 10? (and only that record) SELECT ALL FROM blogs WHERE id = 10 SELECT id FROM blogs WHERE id = 10 SELECT * FROM blogs WHERE id = 10 SELECT id = 10 FROM blogs

SELECT * FROM blogs WHERE id = 10

You have a database with a blogs table. The blogs table contains multiple records with several columns of data. One of those columns is named post. Which SQL statement will select all post data (and only the post data) from the blogs table? SELECT post FROM blogs SELECT * FROM blogs SELECT ALL FROM blogs SELECT * FROM BLOGS where data = "posts"

SELECT post FROM blogs

Without the proper precautions, SQL statements we create in PHP may be vulnerable to _________________________. CORS (cross-origin resource sharing) attacks CSRF (cross-site request forgery) attacks XSS (cross-site scripting) attacks SQL injection attacks

SQL injection attacks

Everything in Mongoose starts with a _______________. object connection Schema Data Type

Schema

In the following line of code: Person.findOne({ 'name.last': 'Ghost' }, 'name occupation', function (err, person) {...what does 'name.last' tell you about the name field? The name field is { type: String } The name field is an array with a last element. The name field is an object with a last property. The name field is a string.

The name field is an object with a last property.

You have a database with a blogs table. The blogs table contains multiple records with several columns of data. Which SQL statement will properly update an existing record with an id equal to 10 in the blogs table? UPDATE blogs SET post="My cool post.", author="Jane Doe" WHERE id=10 UPDATE blogs (post, author) SET ("My cool post.", "Jane Doe") WHERE id=10 UPDATE blogs SET id=10, post="My cool post.", author="Jane Doe" UPDATE blogs SET post="My cool post.", id=10 WHERE author="Jane Doe"

UPDATE blogs SET post="My cool post.", author="Jane Doe" WHERE id=10

A REST endpoint is also a ______________________. client response URL REST point JSON object

URL

Select the answer that is NOT a PHP data type. Undefined Array Float NULL

Undefined

Oh no! You accidentally committed your code to your git repository with a password in it. Thankfully, you did not push it to Github. You need to undo your last git commit and remove your password before making a new commit. What is a good approach? Use "git log --oneline" to see a simplified log and grab the id of the commit before last. Now use "git revert [commit id]" to unstage all changes that came before that commit. Use "git log --oneline" to see a simplified log and grab the id of the commit before last. Now use "git reset [commit id]" to unstage all changes that came before that commit. Use "git log --oneline" to see a simplified log and grab the id of the last commit. Now use "git reset [commit id]" to unstage all changes that came before that commit. Use "git log --oneline" to see a simplified log and grab the id of the last commit. Now use "git revert [commit id]" to unstage all changes that came before that commit.

Use "git log --oneline" to see a simplified log and grab the id of the commit before last. Now use "git reset [commit id]" to unstage all changes that came before that commit.

If we see API documentation that shows an endpoint like the following: /:color/random What do we know about the endpoint? We know :color represents a parameter within the endpoint URL. We don't know anything. This could literally mean anything. We know :color will cause an error because the colon : symbol does not belong in a URL. We know the REST API will respond with a random color name.

We know :color represents a parameter within the endpoint URL.

Select the TRUE statement: When a file is included with the require statement and PHP cannot find it, the script will continue to execute. When a file is included with the include statement and PHP cannot find it, the script will continue to execute. When a file is included with the import statement and PHP cannot find it, the script will continue to execute. When a file is included with the load statement and PHP cannot find it, the script will continue to execute.

When a file is included with the include statement and PHP cannot find it, the script will continue to execute.

In the following line of code: Person.findOne({ 'name.last': 'Ghost' }, 'name occupation', function (err, person) {...what does Person represent? a document a model an object a record

a model

In PHP, we can access passwords that we stored outside of our code repository with the ___________________ function. json_decode() getenv() getvars() getconfig()

getenv()

A great benefit of PDO is that it __________________________. is about 30x faster than MySQLi. has an exception class to handle any problems that may occur in our database queries. is nearly hacker proof. requires fewer lines of code.

has an exception class to handle any problems that may occur in our database queries.

$x = 5; $y = 10; Select the if statement that will output "Hello!" when $x is equal to 5 or when $y is equal to 10, but will not create output if both are true. if ($x === 5 Or $y === 10) { echo "Hello!"; } if ($x === 5 xor $y === 10) { echo "Hello!"; } if ($x === 5 || $y === 10) { echo "Hello!"; } if ($x === 5 && $y === 10) { echo "Hello!"; }

if ($x === 5 xor $y === 10) { echo "Hello!"; }

$myArray = array("coffee","espresso","latte"); What type of PHP array is $myArray? multidimensional indexed sorted associative

indexed

The $this keyword is only available inside __________________. properties private functions public functions methods

methods

You can emit or "fire" any event you want with Node.js. Select the correct syntax to emit the "boom" event. myEmitter.fire('boom'); myEmitter.once('boom') myEmitter.on('boom', () => emit('boom')); myEmitter.emit('boom');

myEmitter.emit('boom');

We have a function named addTwo defined like this: const addTwo = (num1, num2) => num1 + num2; Select the correct syntax to call the function with the required parameters when the "add" event is fired. const a = 24; const b = 42; myEmitter.on('add', addTwo(a, b)); const a = 24; const b = 42; myEmitter.on('add', (a,b) => addTwo(num1, num2)); const a = 24; const b = 42; myEmitter.on('add', (num1, num2) => addTwo(num1, num2)); const a = 24; const b = 42; myEmitter.on('add', (a, b) => addTwo(a, b));

myEmitter.on('add', (a, b) => addTwo(a, b));

With JavaScript, we use dot notation to access values within an object. With PHP, instead of dot notation, the syntax for access values held within an object looks like this: ________________. myObject->get_name() myObject>>get_name() myObject::get_name() myObject+=get_name()

myObject->get_name()

When we create an object, we use the _______________ keyword. get class set new

new

When a callback is passed to the get() method (or similar methods) in Express, it always has request and response parameters. It may also have a third parameter. What is the likely third parameter? next route this function

next

What folder does npm create and use to store packages in your project? node_index node_code node_modules node_packages

node_modules

With NPM, you can run packages without downloading using ________________________. npm install npx npm update npm @latest

npx

If you see... title: String, ...inside a Mongoose Schema, what is it shorthand for? {model: String} {data: String} {body: String} {type: String}

{type: String}


Kaugnay na mga set ng pag-aaral

Abnormal Psych Exam 1 Ch 5 Mood Disorders

View Set

Pharm Test 5 Chp 14, 57-59, Ap. A & B)

View Set

Psychology 2000 Alex Cohen Exam 1 LSU

View Set

130. Stock Dividends and Splits (do MC questions)

View Set

Chapter 9(inquizitive) Political Partiez

View Set