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 PHP & Databases with PDO PDO Database Security PHP & Databases with PDO

what is a pdo object

What is a PDF object and how do I add it to my code?

index.php
<?php

//Place your code below this comment


?>

1 Answer

Daniel Gauthier
Daniel Gauthier
15,000 Points

Hey Daniel,

PDO (PHP Data Objects) is the newest method of communicating with databases in PHP. It's a highly recommended method over the older mysql and mysqli methods, although a case could be made for learning mysqli.

Generally, if you're just getting started in PHP, choosing one or the other to learn and get comfortable with would likely be the best way to keep yourself from becoming confused. Both methods have upsides and downsides, but I would personally recommend learning PDO as it will only become more prevalent as time goes on.

That being said, in order to complete the first part of the challenge, you create the object as if you're declaring a variable.

The working code is:

<?php

//Place your code below this comment

$db = new PDO( 'sqlite::memory:' ); 

?>

This code creates the PDO object by using the keyword new to create a PDO object with the name of sqlite::memory: and assigning the object to the variable $db.

Good luck with the course!