There must be things you're not showing for your code to work anywhere. First is the class definition for 'DB' which is not part of PDO that I could find. Second is the '$dsn' string. They may be part of an include file somewhere on another project.
The code below is what I got from Pear/PDO. The complete example above with the info for my database works exactly the same as the direct method that I used before which is like you showed above using 'mysql_connect'.