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 Integrating PHP with Databases Using Relational Tables Using a Prepared Statement

Thomas Morling
Thomas Morling
12,754 Points

PDO prepared statement. I am stumped on member_id single argument. What is being asked?

<?php function get_member() { include("connection.php");

try {
  $results = $db->prepare(
      "SELECT member_id, email, fullname, level
      FROM members WHERE member_id = ?"
  );

  $results->bind_param('s', $member_id, PDO::PARAM_INT);
  $results->execute();

} catch (Exception $e) {
  echo "bad query";
}

$members = $results->fetchAll();
return $members;

}

index.php
<?php
function get_member() {
    include("connection.php");

    try {
      $results = $db->prepare(
          "SELECT member_id, email, fullname, level
          FROM members WHERE member_id = ?"
      );

      $results->bind_param('s', $member_id);
      $results->execute();

    } catch (Exception $e) {
      echo "bad query";
    }

    $members = $results->fetchAll();
    return $members;
}

1 Answer

I believe this quiz is simply asking on Challenge 1 of 3 to make sure that the function receives a variable as an argument before it can be executed. A lot of times the quizzes seem like that want more than they really do, so try just adding the single argument to the function --- Meaning ---

function get_member($member_id) {
///code
}
Thomas Morling
Thomas Morling
12,754 Points

Wow! That was it! Thank you very much!! I definitely was over thinking this one!