brown2005 Posted February 6, 2013 Share Posted February 6, 2013 class Selmgec { function myfunction(){ } } I currently do $selmgec->myfunction();, which I was using with the old way of connecting mysql_ but was adivsed to change to pdo connection, so how do I change my code to make the function work, as currently it is not? Quote Link to comment https://forums.phpfreaks.com/topic/274121-mysql_-to-pdo-and-making-functions-work/ Share on other sites More sharing options...
kicken Posted February 6, 2013 Share Posted February 6, 2013 The only thing that might change in how you call the function is you may need to pass in a handle for the PDO connection, if it's not available via some other means (ie class variable). You just have to update the code within it to use PDO rather than the mysql_* functions. Quote Link to comment https://forums.phpfreaks.com/topic/274121-mysql_-to-pdo-and-making-functions-work/#findComment-1410521 Share on other sites More sharing options...
brown2005 Posted February 6, 2013 Author Share Posted February 6, 2013 class Selmgec { function website_url($url){ global $db; $stmt = $db->query("SELECT selmgec_id FROM selmgec INNER JOIN domains ON selmgec_domain=domains_id WHERE domains_url='$url'"); while($row = $stmt->fetchAll(PDO::FETCH_ASSOC)){ return $row['selmgec_id']; } } function website_id($id){ global $db; $stmt = $db->query("SELECT domains_url FROM domains INNER JOIN selmgec ON selmgec_domain=domains_id WHERE selmgec_id='$id'"); while($row = $stmt->fetchAll(PDO::FETCH_ASSOC)){ return $row['domains_url']; } } } $network = $selmgec->website_url('http://www.richardbrown.name'); so why is this not working? Quote Link to comment https://forums.phpfreaks.com/topic/274121-mysql_-to-pdo-and-making-functions-work/#findComment-1410571 Share on other sites More sharing options...
kicken Posted February 6, 2013 Share Posted February 6, 2013 Because fetchAll returns an array of rows, yet you're trying to use it as if it returned just a single row. You want to use just fetch instead. Quote Link to comment https://forums.phpfreaks.com/topic/274121-mysql_-to-pdo-and-making-functions-work/#findComment-1410575 Share on other sites More sharing options...
brown2005 Posted February 6, 2013 Author Share Posted February 6, 2013 Because fetchAll returns an array of rows, yet you're trying to use it as if it returned just a single row. You want to use just fetch instead. thank you! Quote Link to comment https://forums.phpfreaks.com/topic/274121-mysql_-to-pdo-and-making-functions-work/#findComment-1410576 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.