Categorieën
Hoe maak ik connectie met MySQL vanuit PHP?
$servername = "JeDbHost";
$username = "DbGebruikersnaam";
$password = "DbWachtwoord";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
$servername = "JeDbHost";
$username = "DbGebruikersnaam";
$password = "DbWachtwoord";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>