php prelim Flashcards

1
Q

Which of the following represent a header for the mail() function?

A

“From: example@example.com”
“Subject: Important Message”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which two commands convert HTML tags to plain text?

A

html_entity_decode()
strip_tags()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which user-defined function sorts an array by keys?

A

ksort()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the result of the command intdiv(9, 2)?

A

4
theres never a reminder and it rounds down

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the result ofthe following code: echo $today = date(“d/m/y”);?

A

“09/10/23”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are two effects of the sizeof(array) command?

A

Returns the number of elements in the array.
Returns the amount of memory (in bytes) used by the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the outcome of the given code snippet: $stack = array(“orange”, “banana”, “apple”,
“raspberry”); $fruit = array_pop($stack);?

A

$fruit = array_pop($stack); // $fruit contains “raspberry” and $stack is modified to [“orange”,
“banana”, “apple”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the proper sequence of steps to create an IF condition?

A

Condition, True Block, Optional Else Block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following are considered logically false values? (Choose 3)

A

false
null
0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of IntlChar?

A

IntlChar is a PHP extension that provides functions to work with Unicode characters andstrings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of the following represents a Null coalescing operator?

A

??

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the proper sequences of steps to establish a FOR condition?

A

Initialization, Condition, Increment/Decrement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the outcome of the given code: $x = 0; do { echo “$x”; $x++; } while ($x != 10);?

A

The code will print numbers from 0 to 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which three events terminate a session?

A

Closing the browser
Calling session_destroy()
Timeout due to inactivity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which PDO function safeguards against threats such as SQL injections?

A

PDO::prepare

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which query retrieves the city and average age of cities with an average age greater than 30 years?

A

SELECT city, AVG(age) AS avg_age FROM citiesWHERE avg_age > 30

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which of the following retrieves a value from a page indirectly?

A

$_SESSION

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are two outcomes ofthe PDOStatement::fetchObjectstatement?

A

Retrieves the specified column values as object properties.
Fetches the next row from a result set as an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are two effects of the session_destroy() function?

A

Ends the current session and closes the browser.
Deletes all data associated with the current session.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the result of the following code? $sth = $dbh->prepare(“SELECT name, color FROM “fruit”);
@colcount = $sth->columnCount();

A

The code will generate a syntax error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

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] . “-“;
}
}

A

“Alfa Romeo-37-35-“

21
Q

What does the memory_limit() parameter control in PHP?

A

The maximum amount of memory a PHP script can consume

22
Q

What is the primary distinction between MySQL and MariaDB?

A

MySQL is closed-source, while MariaDB is open-source.

23
Q

In which layer of the protocolstack is the acronym “www” typically found?

A

Application Layer

24
Which two commands retrieve all data for reservations made by customers who live in Milan, where Customers:= and Reserv:=
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';
25
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';
26
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;
27
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;
28
Which statement allows you to retrieve a list of all tables in a database?
SELECT * FROM information_schema.tables WHEREtable_schema = 'your_database';
29
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.
30
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
31
What does the code $a % $b do?
Calculates the remainder when $a is divided by $b.
32
What does the escape sequence \0 represent?
Null character ASCII value zero
33
Which two URLs enable the display of a dynamic page?
http://example.com/index.php http://example.com/dynamic-page
34
Which function can be used to check if a form field is incomplete?
empty()
35
Which of the following retrieves a value from a URL?
$_GET
36
Which two functions can be used to prevent SQL injection attacks?
mysqli_real_escape_string() PDO::prepare()
37
Which of the following are NOT allowed in a variable declaration?
Special characters like ! or @ Spaces Keywords such as "if" or "else"
38
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.
39
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.
40
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.
41
What is the purpose of the mysqli_query() function in PHP when working with MySQL databases?
To execute SQLqueries on a MySQLdatabase.
42
In PHP, how can you retrieve data from a form submitted using the POST method?
By using the $_POST superglobal array.
43
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.
44
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.
45
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().
46
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
47
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.
48
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.
49
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