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

PHP

Wrong answer is the right answer in quiz after video.

In the PDO Security quiz of PHP & Databases with PDO, the question asked is: What do I need to call on a PDOStatement object after I've bound the parameters? It says the right answer is exec(), which I don't think is right. The answer should be the execute() method.

PDO::exec() does exists (http://php.net/manual/en/pdo.exec.php) but it is a PDOStatement, not a method of one as far as I can tell.

2 Answers

Howdy Folks, this has been updated! Thank you. Please see this thread for any further questions.

Hugo Paz
Hugo Paz
15,622 Points

Hi Josh,

If you look at the examples provided in that page you can see that the ps->exec() is correct.

PDO::exec() is how you can access a property or method of a class. If you create an object from that class, you access its methods or properties with ->

You are right about being able to use exec() on a PDO object but not in this situation since you are calling on a PDOStatement object. When I test exec() on a prepared statement I get:

Fatal error: Call to undefined method PDOStatement::exec()

If I use execute() it works. Preceding this question, the video teaches you this code:

$results = $db->prepare('SELECT * FROM film WHERE film_id = ?'); $results->bindParam(1, $film_id); $results->execute();

So it seems relevant that this question would be asked and the right answer would be execute(), since exec() hasn't been taught in any of the previous lessons.

Hugo Paz
Hugo Paz
15,622 Points

Seeing the code you posted i believe you are correct. I will contact support about this issue.