Connecting to MySQL using PHP

MySQL Scripting With PHP

Connecting and interacting with a MySQL database using PHP or any other language is a fairly complex topic. This code example provides a simple way to test your connection and provides one particuar way to structure your MySQLi object in order to properly connect to your MySQL server.

$mysqli_connection = new MySQLi('your_host.u.washington.edu', 'root', 'your_password', 'your_db', your_port);
if($mysqli_connection->connect_error){
   echo "Not connected, error: ".$mysqli_connection->connect_error;
}
else{
   echo "Connected.";
}

Resources

Last modified: August 15, 2013