The connection page
Answers are for parents and teachers.
1
Write four PHP lines that store the four connection facts for a database called dbclub, using an invented user and a placeholder password.
$server = "localhost"; $user = "club_user"; $password = "a-long-secret"; $database = "dbclub";
2
A pupil writes: if ($connect) { … } else { echo "not connected"; } after mysqli_connect. Explain why the else part is never used in PHP 8.1 and later, and what to use instead.
A failed mysqli_connect throws an exception instead of returning false. Use try and catch (mysqli_sql_exception).
3
Which of these should never be shown to a visitor: (a) the sentence “Please try again later”, (b) the password, (c) the server’s full error text?
(b) and (c).
4
Give two reasons why the connection code lives in one included file.
Every page needs it, so it is not repeated; a change of password or server is made in one place.
5
What is the use of a character set in the connection?
It lets Arabic and English letters be stored and shown correctly.