Undefined method PDO::setAttibute()

hey all,

I’m working through kevin yank’s PHP&MySQL: Novice to Ninja and am stuck at chapter 4 where we connect to the MySQL database from PHP for the first time:

<?php
try
{
	$pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdb', 'mypassword');
	$pdo->setAttibute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
	$output = 'Unable to connect to the database server.';
	include('output.html.php');
	exit();
}

$output = 'Database connection established.';
include('output.html.php');	
?>

if i comment out the lines

//	$pdo->setAttibute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//	$pdo->exec('SET NAMES "utf8"');

the connection goes flawlessly. however, with those two lines, i get the error message:

Fatal error: Call to undefined method PDO::setAttibute() in /Applications/MAMP/htdocs/connect/index.php on line 5

please advise :slight_smile:

cheers,

marco

There is a typo lol, it should be setAttribute, not setAttibute.

What version of PHP are you running?

Edit:

Seems Hall of Famer caught something I even missed :smiley:

Gotta admit the first thing that came to my mind was the PHP version too, but once I realized that PDO’s methods are available since PHP 5.1 I knew that typo was the only alternative cause of such problems. XD

:open_mouth: d’oh.

apologies… /crawls back into his newbie cave

Please don’t crawl back in there. We like newbie questions :smiley: Rather it be something glaringly obvious sometimes than something impossibly difficult :slight_smile:

thanks to all for your answers!