php prelim Flashcards
Which of the following represent a header for the mail() function?
“From: example@example.com”
“Subject: Important Message”
Which two commands convert HTML tags to plain text?
html_entity_decode()
strip_tags()
Which user-defined function sorts an array by keys?
ksort()
What is the result of the command intdiv(9, 2)?
4
theres never a reminder and it rounds down
What is the result ofthe following code: echo $today = date(“d/m/y”);?
“09/10/23”
What are two effects of the sizeof(array) command?
Returns the number of elements in the array.
Returns the amount of memory (in bytes) used by the array
What is the outcome of the given code snippet: $stack = array(“orange”, “banana”, “apple”,
“raspberry”); $fruit = array_pop($stack);?
$fruit = array_pop($stack); // $fruit contains “raspberry” and $stack is modified to [“orange”,
“banana”, “apple”]
What is the proper sequence of steps to create an IF condition?
Condition, True Block, Optional Else Block.
Which of the following are considered logically false values? (Choose 3)
false
null
0
What is the purpose of IntlChar?
IntlChar is a PHP extension that provides functions to work with Unicode characters andstrings
Which of the following represents a Null coalescing operator?
??
What is the proper sequences of steps to establish a FOR condition?
Initialization, Condition, Increment/Decrement
What is the outcome of the given code: $x = 0; do { echo “$x”; $x++; } while ($x != 10);?
The code will print numbers from 0 to 9
Which three events terminate a session?
Closing the browser
Calling session_destroy()
Timeout due to inactivity
Which PDO function safeguards against threats such as SQL injections?
PDO::prepare
Which query retrieves the city and average age of cities with an average age greater than 30 years?
SELECT city, AVG(age) AS avg_age FROM citiesWHERE avg_age > 30
Which of the following retrieves a value from a page indirectly?
$_SESSION
What are two outcomes ofthe PDOStatement::fetchObjectstatement?
Retrieves the specified column values as object properties.
Fetches the next row from a result set as an object
What are two effects of the session_destroy() function?
Ends the current session and closes the browser.
Deletes all data associated with the current session.
What is the result of the following code? $sth = $dbh->prepare(“SELECT name, color FROM “fruit”);
@colcount = $sth->columnCount();
The code will generate a syntax error
What is the result of the following code?
$auto = array (array(“Fiat”,24,13), array(“Ferrari”,45,33), array(“Jeep”,54,23), array(“Alfa
Romeo”,37,35));
for ($row = 3; $row < 4; $row++) {
for ($col = 0; $col < 3; $col++) {
echo $auto[$row][$col] . “-“;
}
}
“Alfa Romeo-37-35-“
What does the memory_limit() parameter control in PHP?
The maximum amount of memory a PHP script can consume
What is the primary distinction between MySQL and MariaDB?
MySQL is closed-source, while MariaDB is open-source.
In which layer of the protocolstack is the acronym “www” typically found?
Application Layer
Which two commands retrieve all data for reservations made by customers who live in Milan, where
Customers:=<Cod_cust, Surname,Name,Town, Salary, Age> and Reserv:=<Cod_cust, Cod_alb, Room,
Days, Account>
SELECT * FROM Reserv INNER JOIN Customers ON Reserv.Cod_cust =Customers.Cod_cust WHERE Customers.Town = ‘Milan’;
SELECT * FROM Reserv, Customers WHEREReserv.Cod_cust = Customers.Cod_cust AND Customers.Town = ‘Milan’;
Which statement grants the user “user” full permissions for the “Display” database using the
password “1234”?
GRANT ALL PRIVILEGES ON Display TO ‘user’@’localhost’ IDENTIFIED BY ‘1234’;
Which query returnsthe town and the maximum salary for each town that has an average age of less
than 35 years?
SELECT town, MAX(salary) FROM towns GROUP BY town HAVING AVG(age) < 35;
Which query provides the town name and the number of customers from each town, sorted by the
number of customers?
SELECT town, COUNT(*) AS num_customers FROM customers GROUP BY town ORDER BY num_customers DESC;
Which statement allows you to retrieve a list of all tables in a database?
SELECT * FROM information_schema.tables WHEREtable_schema = ‘your_database’;
What is the outcome of the following code?
$fruits = array(“lemon”, “orange”, “banana”, “apple”); rsort($fruits);reset($fruits); while (list($ky,
$value) = each($fruits)) { echo “fruits[” . $key . “] = “ . $value . “\n”; }
It will display nothing.
Which of the following indicates a comment?
(hashtagsymbol)This is a comment.
one only works in php and no other languages but the others also work in php
What does the code $a % $b do?
Calculates the remainder when $a is divided by $b.
What does the escape sequence \0 represent?
Null character ASCII
value zero
Which two URLs enable the display of a dynamic page?
http://example.com/index.php
http://example.com/dynamic-page
Which function can be used to check if a form field is incomplete?
empty()
Which of the following retrieves a value from a URL?
$_GET
Which two functions can be used to prevent SQL injection attacks?
mysqli_real_escape_string()
PDO::prepare()
Which of the following are NOT allowed in a variable declaration?
Special characters like ! or @
Spaces
Keywords such as “if” or “else”
In PHP, what is the purpose of the header() function, and how is it commonly used?
To send HTTP headers to the browser and control redirection.
What does the term “SQL injection” refer to in the context of database security, and how can it be
prevented?
SQL injection is a vulnerability that allows attackers to manipulate SQL queries through userinputs.
How can you connectto a MySQLdatabase using PHP, and what function is commonly used for this
purpose?
You can connect to a MySQL database using the mysqli_connect() function.
What is the purpose of the mysqli_query() function in PHP when working with MySQL databases?
To execute SQLqueries on a MySQLdatabase.
In PHP, how can you retrieve data from a form submitted using the POST method?
By using the $_POST superglobal array.
Whatis the difference between mysqli and PDO when connecting to databases in PHP, and why might you choose one over the other?
mysqli is used for MySQL databases, while PDO supports multiple database types.
In MySQL, what is a primary key, and why is it important in database design?
A primary key is a unique identifier for a table’s rows and ensures data integrity.
How can you prevent SQL injection in PHP when processing user inputs in SQL queries?
By validating and escaping user inputs using functions like mysqli_real_escape_string().
What does the PHP foreach loop do, and how is it commonly used?
The foreach loop iterates over elements in an array or other iterable objects
What is the difference between mysql_ functions and mysqli_ functions in PHP when working with
MySQL databases?
mysqli_ functions are more modern and provide better security features and support for multiple statements and transactions.
How can you create a new database in MySQL using PHP, and which SQL statement is commonly used for this purpose?
You can create anew database using the mysqli_query() function with the CREATEDATABASESQL statement.
In PHP, what is the purpose of the implode() function, and how is it commonly used when working with arrays?
The implode() function is used to join array elements into a string