Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

2nd MySQL Dataset not working

$
0
0

I have a function:
 

//----------------------------------------------------------------------
$server_name='xxx';
$user_name='xxx';
$password='xxx';
$database_name='xxx';
$db1= new mysqli($server_name, $user_name, $password, $database_name);
//----------------------------------------------------------------------

function get_dataset($db1, $query_string) {
//---------------------------------------------------------------------
$result1 = $db1->query($query_string);
//$num_results = $result1->num_rows;

$num_results = $result1->num_rows;

$res_array = array();

for ($count=0; $row = $result1->fetch_assoc(); $count++) {
$res_array[$count]=$row;
}

return $res_array;


//$result8 = db_result_to_array($result1);
//return $result1;
$query_string->free();
$result1->free();
//$db1->close();
}
//---------------------------------------------------------------------

Now, this works fine, sort of....

On a separate page, I call the function:
 

$result=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")");

This works fine, however, I also have a few comboboxes I want to pull datasets into. This wasn't working, so just to test, I tried the following:
 

$result=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")");

$result2=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")");

So the 2nd, is simply a copy/paste of the first, yet it returns this error:

Fatal error: Call to a member function fetch_assoc() on a non-object in FILE PATH\functions.php on line 33

(line 33 being the line including fetch_assoc() in the function get_dataset, shown above).

Now, from this, I'm assuming somehow my dataset isn't clearing properly, or something like that. If I call the function once it works, twice it doesn't.

This is really bugging me and has been for weeks now, so I'd really appreciate it, if anyone could help out!!!


Viewing all articles
Browse latest Browse all 13200

Trending Articles