I am trying to connect to a database with PHP PDO and i keep getting this: "Error: No database selected". The code i had before PDO was working just fine. Can anyone see what i'm doing wrong? I am new to PDO.
Old Code:
$dbHost = 'localhost:3306'; $dbUser = 'username'; $dbPass = 'password'; $dbName = 'database_name'; $dbconn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to the database!'); mysql_select_db($dbname); PDO Code:
$dbHost = 'localhost'; $dbUser = 'username'; $dbPass = 'password'; $dbName = 'database_name'; $dbconn = new PDO('mysql:host=$dbHost;port=3306;dbname=$dbName', $dbUser, $dbPass);