early return if there is no rows returned. Improve debug when there is a row but the specified column isn't present

This commit is contained in:
Isaac Connor 2018-02-02 10:27:30 -05:00
parent 40379f7df6
commit 929e49c301
1 changed files with 5 additions and 1 deletions

View File

@ -153,11 +153,15 @@ function dbFetchOne( $sql, $col=false, $params=NULL ) {
Error( "SQL-ERR dbFetchOne no result, statement was '".$sql."'" . ( $params ? 'params: ' . join(',',$params) : '' ) );
return false;
}
if ( ! $result->rowCount() ) {
# No rows is not an error
return false;
}
if ( $result && $dbRow = $result->fetch( PDO::FETCH_ASSOC ) ) {
if ( $col ) {
if ( ! isset( $dbRow[$col] ) ) {
Warning( "$col does not exist in the returned row" );
Warning( "$col does not exist in the returned row " . print_r($dbRow, true) );
}
return $dbRow[$col];
}