MySQL DatabaseLesson 58Free preview
MySQL Connect
This lesson is part of PHP · All levels
Summary
Before manipulating data, PHP must open a connection to a MySQL server using the mysqli_connect() function or PDO object. This function accepts host, username, password, and database name as the primary parameters. Successful connections should always be checked and closed again after use.
Key points
- Open the connection and restore the connection resource.
- The connection results are required to be checked to quickly detect any credential errors.
- Mysqli_select_db() or the fourth parameter determines the active database.
- Close the connection with mysqli_close() and keep the credentials outside the public file.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.