1. 程式人生 > >PHP connects Hostinger MySQL database

PHP connects Hostinger MySQL database

After registering my domain on Hostinger, I tried to connect the Hostinger MySQL database from PHP script. Be careful about the server name:

<?php
	$servername = "localhost"; // work
	$servername = "mysql.hostinger.com"; // not work
	$servername = "182.12.24.1"; // not work
	$username = "uxxxx_xxx";
	$password = "xxxxxx";
	$dbname = "uxxxx_xxx";

	// create connection
	$conn = mysqli_connect($servername, $username, $password, $dbname);

	// check connection
	if (!$conn) {
		die("Connection failed: " . mysqli_connect_error());
	}
?>