albmed7589 Posted July 14, 2016 Share Posted July 14, 2016 (edited) This is my code $stmt = $db->prepare("SELECT factory FROM offices WHERE id=?"); $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($factory); echo "<br />factory: ".$factory; problem is there is no value being assigned to the $factory variable. when I run the query in PHPMyAdmin I get back one result, as expected. Any help would be highly appreciated Edited July 14, 2016 by albmed7589 Quote Link to comment https://forums.phpfreaks.com/topic/301475-simple-php-sql-query-help/ Share on other sites More sharing options...
lovephp Posted July 14, 2016 Share Posted July 14, 2016 Shouldn't this $stmt->bind_param("i", $id); Be $stmt->bind_param("id", $id); ?? Quote Link to comment https://forums.phpfreaks.com/topic/301475-simple-php-sql-query-help/#findComment-1534474 Share on other sites More sharing options...
mac_gyver Posted July 14, 2016 Share Posted July 14, 2016 (edited) you are missing a $stmt->fetch(); method call to retrieve the data. the PDO extension is much more consistent and straight-forward to use, particularity with prepared queries. if you can, switch from using the mysqli extension to the PDO extension. Edited July 14, 2016 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/301475-simple-php-sql-query-help/#findComment-1534475 Share on other sites More sharing options...
ginerjm Posted July 14, 2016 Share Posted July 14, 2016 LovePHP: mysqli requires the variable type to do the bind using the ? parm. Therefore the OP's code is correct as it is. Mac_gyver has solved the user problem - no data was being fetched. And Mac_gyver has my vote on his choice of PDO over mysqli! Quote Link to comment https://forums.phpfreaks.com/topic/301475-simple-php-sql-query-help/#findComment-1534479 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.