Jump to content

Recommended Posts

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.

Edited by KubeR
Link to comment
https://forums.phpfreaks.com/topic/291991-mysqli-store_result-fail/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.