Connecting PHP to MySQL on Loopia hosting is done with the mysqli extension and the database credentials shown in the Loopia Customer Zone. This article provides a minimal connection example using the object-oriented mysqli API. Replace the placeholder host, username, password and database name with the values issued to you in your Customer Zone.
Example: connect to MySQL with mysqli
$mysql_host = "mysqlserver.loopia.se"; /* Change to correct hostname, such as mysql369.loopia.se */
$mysql_user = "your_user";
$mysql_password = "your_password";
$mysql_database = "database_name";
$mysqli = new mysqli( $mysql_host, $mysql_user, $mysql_password, $mysql_database );
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
The correct value for $mysql_host (for example mysql369.loopia.se) is shown next to the database in the Loopia Customer Zone under “Databases”.