Connecting to a MySQL Database
MySQLi
We will be using mysqli (or MySQL improved extension)
This was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer.
The mysqli extension is included with PHP versions 5 and later.
Benefits over the previous MySQL:
Object-oriented interface
Support for Prepared and Multiple Statements
Support for Transactions
Enhanced debugging capabilities
Embedded server support
Connecting to a Database - Example
The php code below will connect to a server called localhost and connect to the database called AH_phpskills. It will use the username of root with no password.
If the connection fails for any reason then an error description is displayed using the mysqli_connect_error() function and the die() function stops the script from running.