narjis Posted June 7, 2011 Share Posted June 7, 2011 I am opening a connection with mysqli and passing the returning object to another function which returns the array of the object passed but it is not giving correct result. Here is the code: function convert_to_array($arrObj){ $res_array = array(); for ($count=0; $row = $arrObj->fetch_assoc(); $count++){ $res_array[$count] = $row; } return $res_array; } function getUser($email,$pass) { $conn = db_connect(); $query ="select * from users where Password='".$pass."' and Email='".$email."'"; $result = @$conn->query($query); $num = @$result->num_rows; if($num==0) echo "NoT OK"; else{ echo "OK"; $result = convert_to_array($result); echo ("$num"); return $result; }function getUser($email,$pass) { $conn = db_connect(); $query ="select * from users where Password='".$pass."' and Email='".$email."'"; $result = @$conn->query($query); $num = @$result->num_rows; if($num==0) echo "NoT OK"; else{ echo "OK"; $result = convert_to_array($result); echo ("$num"); return $result; } Quote Link to comment https://forums.phpfreaks.com/topic/238625-unable-to-return-array/ Share on other sites More sharing options...
GingerRobot Posted June 7, 2011 Share Posted June 7, 2011 Well the first thing I notice is that you're suppressing errors on the function calls. Are you sure you wanted to do that? What happens if your query is not executed successfully? Quote Link to comment https://forums.phpfreaks.com/topic/238625-unable-to-return-array/#findComment-1226313 Share on other sites More sharing options...
narjis Posted June 7, 2011 Author Share Posted June 7, 2011 It returns true for the valid user but does not convert this object to array. Quote Link to comment https://forums.phpfreaks.com/topic/238625-unable-to-return-array/#findComment-1226341 Share on other sites More sharing options...
mikosiko Posted June 7, 2011 Share Posted June 7, 2011 take the @ out of your calls to functions as was suggested. in the code that you posted...is there a copy/paste problem?.. you have the function getUser() twice ...which returns the array of the object passed but it is not giving correct result... why?... details... Quote Link to comment https://forums.phpfreaks.com/topic/238625-unable-to-return-array/#findComment-1226472 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.