doucie Posted March 27, 2007 Share Posted March 27, 2007 @$db = new mysqli_connect('localhost','root','','restaurant'); if(mysqli_connect_errno()) { echo 'Could not connect to the database'; exit; } $query="SELECT name FROM ingredients"; $result=$mysqli_query($db,$query); $num_results=mysqli_num_rows($result); echo $num_results; I would expect this to echo out a number, but it does nothing, not even an error. Help! Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/ Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 remove the @ from infront of the mysqli connection line. Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/#findComment-216306 Share on other sites More sharing options...
doucie Posted March 27, 2007 Author Share Posted March 27, 2007 Cheers. The book I'm reading has an @. Hopefully not too many typos! Ive removed the @ but now get the following error Function name must be a string in C:\wamp\www\reporting\my_functions.php on line 13 Line 13 is $result=$mysqli_query($db,$query); Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/#findComment-216316 Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 We need more than just line 13 bud. Post at least the first 50 lines so we can look at it more indepth. Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/#findComment-216317 Share on other sites More sharing options...
Barand Posted March 27, 2007 Share Posted March 27, 2007 It looks like you can't make up your mind whether to to use mysqli in its object style or its proceduaral style. You can either call $db = new mysqli('localhost', 'root', '', 'restaurant'); and then use the class methods or use the procedural style, as the rest of your code does, with $db = mysqli_connect('localhost', 'root', '', 'restaurant'); Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/#findComment-216321 Share on other sites More sharing options...
doucie Posted March 27, 2007 Author Share Posted March 27, 2007 Barand - Changed that line to procedural, like the rest. Still get the same error All the code below function get_ingredients() { echo 'All the ingredients are listed below.'; $db=mysqli_connect('localhost','root','','restaurant'); if(mysqli_connect_errno()) { echo 'Could not connect to the database'; exit; } $query="SELECT name FROM ingredients"; $result=$mysqli_query($db,$query); $num_results=mysqli_num_rows($result); echo $num_results; } Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/#findComment-216323 Share on other sites More sharing options...
per1os Posted March 27, 2007 Share Posted March 27, 2007 $result=$mysqli_query($db,$query); should be $result=mysqli_query($db,$query); no $ infront of functions. Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/#findComment-216327 Share on other sites More sharing options...
doucie Posted March 27, 2007 Author Share Posted March 27, 2007 Nice one, fixed. Thanks all. Quote Link to comment https://forums.phpfreaks.com/topic/44536-solved-help-with-getting-data/#findComment-216330 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.