Sql Flashcards

1
Q

$db_server = “localhost”;
$db_user = “root”;
$db_password = “”;
$db_name = “demodb”;
$conn = “”;

A

These variables store the needed credentials to connect to a MySQL database server and select a specific database.

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

How would you establish a connection to a MySQL database using the following PHP code:

$db_server = “localhost”;
$db_user = “root”;
$db_password = “”;
$db_name = “businessdb”;
$conn = “”;

A

$conn = mysqli_connect($db_server, $db_user, $db_password, $db_name);

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

Explain the role of the empty string assignment to the variable $conn in the provided PHP code.

$db_server = “localhost”;
$db_user = “root”;
$db_password = “”;
$db_name = “businessdb”;
$conn = “”;

A

The empty string assignment initializes the variable $conn to an empty value, indicating that it will hold the connection object once the connection to the database is established using mysqli_connect(). This approach is commonly used to initialize variables in PHP.

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