Trying to get the hang of PDO
Hi Guys!
Lisa's back with her super dumb question time!
I'm trying to get the hang of PDO, and I understand that it'll be easier for my DB Connections in the future, but there are just some (probably basic) things that I'm getting stuck on.
Let's say I have this in my class
The goal is to 1) pull the customer's login information for $network out of our database and display it for them on the page (we really try and dumb things down for them), and 2) set $username, $password, and $profile_url, which are data members for my class, with their initial values.
Would the values bound $username, $password, and $profile_url persist after the while loop has ended? Or because of the use of bindColumn, would the values be trashed? Or do I even need the while loop at all? Some of the things I'm reading seem to conflict as to whether or not I need it.
Thanks again!
Lisa's back with her super dumb question time!
I'm trying to get the hang of PDO, and I understand that it'll be easier for my DB Connections in the future, but there are just some (probably basic) things that I'm getting stuck on.
Let's say I have this in my class
private $_db = new PDO;
$network_name;
$username;
$password;
$profile_url;
__constructor($client_id, $network)
{
$_db = PDO(connection_string_info_you_dont_get_to_see);
$query = "SELECT * FROM social_media ";
$query .= "WHERE client_id = " . $client_id . " AND network_name = " . $network . " ";
$query .= "LIMIT 0, 1;";
try
{
$result = $_db->query($query);
$result->bindColumn('username', $username);
$result->bindColumn('password', $password);
$result->bindColumn('profile_url', $profile_url);
$network_name = $network;
while ($row = $result->fetch(PDO_FETCH_BOUND))
{
//Stuff I haven't thought of yet goes here
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}The goal is to 1) pull the customer's login information for $network out of our database and display it for them on the page (we really try and dumb things down for them), and 2) set $username, $password, and $profile_url, which are data members for my class, with their initial values.
Would the values bound $username, $password, and $profile_url persist after the while loop has ended? Or because of the use of bindColumn, would the values be trashed? Or do I even need the while loop at all? Some of the things I'm reading seem to conflict as to whether or not I need it.
Thanks again!
