Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Unsubscribed User
22,441 PointsPDO Class - Error
Hi! I've made a website and declared a new PDO object to connect to the database but the browser displays an error and says PDO is a unknown class..
This is the php code I'm currently writing..
$user = "the user of my database";
$pass = "my database password";
try {
$db = new PDO('dblib:host=localhost;dbname=clubli7_clublife;charset=UTF-8', $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$db->exec("SET NAMES 'utf8'");
} catch (Exception $e) {
echo "Could not connect to the database.";
exit;
}
What should I do?
6 Answers
Gareth Borcherds
9,372 PointsTypically an unknown class error comes from php not seeing the class in the current script. Did you include the class script somewhere? You should have something like include('file name of pdo class.php');
Mike Wojtkowski
8,245 PointsYou need to have the PDO driver installed for the server. if you have access to apache php.ini check if you have extension=php_pdo_mysql.dll enabled (without semicolon before it). You can locate your phpini file with <?php phpinfo();?>
Unsubscribed User
22,441 PointsI found it. But i enable it and I still get the Fatal Error... :(
Mike Wojtkowski
8,245 PointsDon't forget to restart apache server after you made change in php.ini
Unsubscribed User
22,441 PointsOk, perfect. Where can I restart the apache server? From cpanel?
Mike Wojtkowski
8,245 PointsIf you're using XAMPP for example you should have control panel, just stop / start Apache module.