goldfishdancer Posted March 4, 2013 Share Posted March 4, 2013 this is the code with bind_result: function getUserDetails($username=NULL, $id=NULL) { if($username!=NULL) { $column = "user_name"; $data = $username; } elseif($id!=NULL) { $column = "id"; $data = $id; } global $db; $query = $db->prepare("SELECT id, username, permissions, forename, surname, password, email, courseid, choiceid, lastlogin, active FROM users WHERE $column = :column"); $query->bindParam(":column", $data); $query->execute(); $query->bind_result ($id, $username, $permissions, $forename, $surname, $password, $email, $courseid, $choiceid, $lastlogin, $active); while ($query->fetch()){ $row = array('id' => $id, 'userlevel' => $permissions, 'username' => $username, 'forename' => $forename, 'surname' => $surname, 'password' => $password, 'email' => $email, 'courseId' => $courseid, 'choiceId' => $choiceId, 'lastlogin' => $lastlogin, 'active'=> $active); } return ($row); } I've been trying to convert this to work with PDO, as I've found out that PDO doesnt support bind_result. I've read arround about using fetch assoc but im not entirely sure how to implement it I've tried this: function getUserDetails($username=NULL,$id=NULL) { if($username!=NULL) { $column = "user_name"; $data = $username; } elseif($id!=NULL) { $column = "id"; $data = $id; } global $db; $query = $db->prepare("SELECT id, username, permissions, forename, surname, password, email, courseid, choiceid, lastlogin, active FROM users WHERE $column = :column"); $query->bindParam(":column", $data); $query->execute(); $results = array(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $results[] = $row; } return ($results); } This is a sample of how im trying to use the code $username = '123'; $userdetails = getUserDetails($username); echo $userdetails['surname']; Could anyone please give me a poke in the direction I should be going? I have searched around but I'm just getting more confused. Link to comment https://forums.phpfreaks.com/topic/275197-converting-mysqli-to-pdo-bind_result/ Share on other sites More sharing options...
teynon Posted March 4, 2013 Share Posted March 4, 2013 Try $query->execute(array("column" => $data)); without the bindParam Link to comment https://forums.phpfreaks.com/topic/275197-converting-mysqli-to-pdo-bind_result/#findComment-1416335 Share on other sites More sharing options...
AyKay47 Posted March 4, 2013 Share Posted March 4, 2013 Example#1 in the PHP manual PDOStatement::bindColumn replicates your logic using PDO::FETCH_BOUND mode. Link to comment https://forums.phpfreaks.com/topic/275197-converting-mysqli-to-pdo-bind_result/#findComment-1416338 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.