Page 1 of 1
exec_sql_query(DB_NAGIOSQL, $sql)
Posted: Thu Jun 04, 2015 3:01 pm
by briannd81
I tried to do a "select * from tbl_host" using the built-in function exec_sql_query available from /usr/local/nagiosxi/html/includes/db.inc.php.
exec_sql_query(DB_NAGIOSQL, $sql)
However, it only returns the "first" row.
The table itself, however, has 1139 rows and I'm expecting all 1139 rows to be returned.
Please advise.
Re: exec_sql_query(DB_NAGIOSQL, $sql)
Posted: Thu Jun 04, 2015 3:16 pm
by tmcdonald
What's the exact $sql value? How are you displaying/viewing the results?
Re: exec_sql_query(DB_NAGIOSQL, $sql)
Posted: Thu Jun 04, 2015 3:29 pm
by briannd81
It's my mistake. The solution is posted below.
Originally I had this ... the if will return the first row only.
if (($rs = exec_sql_query(DB_NAGIOSQL, $sql))) {
if (!$rs->EOF) {
print strval($rs->fields["br_num"]) . "\n";
$rs->MoveNext();
}
}
Change if to while to go through all elements of the returned object.
if (($rs = exec_sql_query(DB_NAGIOSQL, $sql))) {
while (!$rs->EOF) {
print strval($rs->fields["br_num"]) . "\n";
$rs->MoveNext();
}
}
Re: exec_sql_query(DB_NAGIOSQL, $sql)
Posted: Thu Jun 04, 2015 3:33 pm
by tmcdonald
I've made that mistake a few times myself
And just for the record, custom code is usually out of scope for the forum. We can help with it, but at some point we might need to point you to a PHP forum.
I'll be closing this thread now, but feel free to open another if you need anything in the future!