I'm learning PHP PDO and at the moment I can connect to my database using the traditional mysql_connect() function but not the using the PHP PDO way.

Here here goes the code using the mysql_connect() function.

HTML Code:
<?php

echo 'This is a test';

/*
database name onetwo_test1
database onetwo_test1 username onetwo_test1u1 with password dbpw123
*/

$host = 'localhost';
$username = 'onetwo_test1u1';
$password = 'dbpw123';
$dbname = 'onetwo_test1';

$conn = mysql_connect($host, $username, $password) or die('Could not connect: ' . mysql_error());

?>
Here goes the code using the PHP PDO way, and yes I know that I should use a try and catch.

HTML Code:
<?php

echo 'This is a test';

/*
database name onetwo_test1
database onetwo_test1 username onetwo_test1u1 with password dbpw123
*/

$host = 'localhost';
$username = 'onetwo_test1u1';
$password = 'dbpw123';
$dbname = 'onetwo_test1';

$conn = new PDO('mysql:host=localhost;dbname=$dbname', $username, $password);
?>
Thanks