I have made a basic database for a grocery store using MySQL.
I would like to make a simple website that uses the data from my database.
I am trying to to use php within a html file to establish a connection to the database.
<!DOCTYPE html>
<?php
$host="127.0.0.1";
$port=3306;
$socket="";
$user="root";
$password="";
$dbname="greenwichgrocers";
try {
$dbh = new PDO("mysql:host={$host};port={$port};dbname={$dbname}", $user, $password));
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>PHP connect to MySQL</h1>
</body>
</html>
The connection code was automatically generated by MySQL Workbench. I am not sure how it is supposed to be formatted as I am completely new to php.
The page will only show this:
Any help would much appreciated