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.
exec_sql_query(DB_NAGIOSQL, $sql)
Re: exec_sql_query(DB_NAGIOSQL, $sql)
What's the exact $sql value? How are you displaying/viewing the results?
Former Nagios employee
Re: exec_sql_query(DB_NAGIOSQL, $sql)
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();
}
}
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)
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!
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!
Former Nagios employee