KubeR Posted October 22, 2014 Share Posted October 22, 2014 Hello, I am trying to send a query and receive data from it, the query is sent successfully and gets the neccessary data, the problem is that store_result returns false if($result=$db->query("SELECT `times_failed` FROM `".$table_prefix."_failed_login` WHERE `ip`='$current_ip' AND `ip2`='$current_ip2'")) { if($result->num_rows) { safe_store("There is an error in the store result'"); } } $result->num_rows returns 1 row I outputted the query using echo SELECT `times_failed` FROM `am_failed_login` WHERE `ip`='127.0.0.1' AND `ip2`='' and tried to send a query using phpMyAdmin and it returned the result as I wanted. The "safe_store" (don't mind the name, I just named it like it) function safe_store($error) { global $db; if(!$db->store_result()) { redirect_error($error); } } I tried to use just $db->store_result(); but it returned Fatal error: Call to undefined method mysqli::free() in C:\xamp\htdocs\projects\lib\functions\user.php on line 310 And fact, that the query returned a result and the num_rows found 1 line in the result. Kaperstone. Link to comment https://forums.phpfreaks.com/topic/291991-mysqli-store_result-fail/ Share on other sites More sharing options...
ginerjm Posted October 22, 2014 Share Posted October 22, 2014 It would be easier to follow your code if we saw it sequentially. Question - you say that num_rows "returns 1 row". Doesn't it return a value of 1 instead? Link to comment https://forums.phpfreaks.com/topic/291991-mysqli-store_result-fail/#findComment-1494424 Share on other sites More sharing options...
KubeR Posted October 23, 2014 Author Share Posted October 23, 2014 What I am trying to do is seperate functions and mysqli connection data into different files. mysqli.php $db = new mysqli(*,*,*,*); function safe_store($error) { global $db; if(!$db->store_result()) { redirect_error($error); } } full function above : function has_execeeded_max_login_fail($max,$times) { global $table_prefix,$db,$current_ip; if($result=$db->query("SELECT `times_failed` FROM `".$table_prefix."_failed_login` WHERE `ip`='$current_ip'")) { if($result->num_rows) { safe_store("2@".$result->num_rows."@".$db->errno."#:".$db->error."@SELECT `times_failed` FROM `".$table_prefix."_failed_login` WHERE `ip`='$current_ip'"); $assoc=$result->fetch_assoc(); if($assoc["times_failed"]==$max) { $return=1; }else{ $return=0; $times=$assoc["times_failed"]; } $db->free(); }else{ $return=0; $times=0; } }else{ redirect_error("1@".$db->error); } return $return; } redirect_error just outputs the error. Link to comment https://forums.phpfreaks.com/topic/291991-mysqli-store_result-fail/#findComment-1494481 Share on other sites More sharing options...
mac_gyver Posted October 23, 2014 Share Posted October 23, 2014 the error message is referring to this line - $db->free(); there is no mysqli free() method. there is however a mysql_result free() method, which for your code would be $result->free(); Link to comment https://forums.phpfreaks.com/topic/291991-mysqli-store_result-fail/#findComment-1494483 Share on other sites More sharing options...
ginerjm Posted October 23, 2014 Share Posted October 23, 2014 which php error checking would have told you. See my signature. Link to comment https://forums.phpfreaks.com/topic/291991-mysqli-store_result-fail/#findComment-1494492 Share on other sites More sharing options...
mac_gyver Posted October 24, 2014 Share Posted October 24, 2014 he's already getting a php error message, but apparently didn't read it or look at the line in his code that's triggering it. Link to comment https://forums.phpfreaks.com/topic/291991-mysqli-store_result-fail/#findComment-1494576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.