wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Connecting to a Database using PHP

Total questions: 9

Worksheet time: 5mins

Name
Class
Date
1.

What does the mysqli_connect command do?

a)

It connects to the web server

b)

It connects to the email server

c)

It connects to the database server

2.

Choose the correct way to use the mysqli_connect() command.


$servername - Address of the Target Database Server

$databasename - Name of the Target Database

$username - User Name

$password - User's Password

a)

mysqli_connect($username, $password, $servername, $databasename)

b)

mysqli_connect($databasename, $servername, $username, $password, )

c)

mysqli_connect($servername, $databasename, $username, $password)

d)

mysqli_connect($servername, $username, $password, $databasename)

3.

In the code above what is the $dbconnection used for?

a)

It is used to check if the connection was false

b)

It is used to store the connection to the database

c)

It is used to check if the connection was successful

d)

It is used to store the database

4.

I have written the following SQL command, what is the command I need to execute to run the SQL?


$sql = "SELECT name, phone, email FROM tblmembers"

a)

mysqli_fetch_assoc($sql)

b)

mysqli_query($dbconnection, $sql);

c)

mysqli_fetch_assoc($dbconnection, $sql)

d)

mysqli_query($sql);

5.

What do you get when you execute the mysqli_query command?

a)

Selected Records from the Web Server

b)

Selected Records from the Database

c)

If the page was successfully loaded

d)

If the query was successfully executed

6.

The above Code has been executed and results in the table have been retrieved


How can I get the Phone number in the results?

a)

$row[2]

b)

$row["Phone"]

c)

$result["Phone"]

d)

$result[2]

7.

Results in the Table above have been retrieved using sqli_query and saved in the $result variable


What will the code output to the HTML page?

a)

Alice John James

b)

$row["regname"] $row["regname"] $row["regname"]

c)

Alice

John

James

d)

$row["regname"]

$row["regname"]

$row["regname"]

8.

Given $results in the table above


$x = mysqli_num_rows($result)


What is the value of x?

a)

3

b)

1

c)

2

d)

4

9.

Which is the correct order for these commands to appear in a typical PHP page


1 - mysqli_query

2 - mysqli_num_rows

3 - mysqli_connect

4 - mysqli_fetch_assoc

a)

3, 2, 1, 4

b)

1, 2, 3, 4

c)

3, 1, 2, 4

d)

3, 2, 4, 1