My code is very simple. I'm attempting to connect to a MySQL instance using pdo_mysql functions. I'm thinking there is a syntax error but the dozens of websites I researched doesn't help me identify it. Below is my code and what is presented on the webpage. Can someone give me some direction?
*** I tried to insert some sites but the app is not letting me.
The pdo_mysql extension is enabled and is displayed in phpinfo.php.
I'm using PHP 7.1.4 on a Windows Server 2012R2 with IIS 8.5
FastCGI is enabled.
Here is my code:
<?php
$username = "myusername";
$password = "mypassword"
$dbname = "mysql"
$hostname = "myserver"
$query = "select user,host from mysql.user";
try {
$dbconn = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$dbconn = null;
?>
The results on the webpage is:
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $dbconn = null; ?>