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. Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/275197-converting-mysqli-to-pdo-bind_result/#findComment-1416335 Share on other sites More sharing options...
Solution AyKay47 Posted March 4, 2013 Solution Share Posted March 4, 2013 Example#1 in the PHP manual PDOStatement::bindColumn replicates your logic using PDO::FETCH_BOUND mode. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.