Avatar of willsherwood
willsherwood

asked on 

mysql -> mysqli utility function conversion to work with mysqli

below is a handy function i inherited that (in the old mysql) allowed a single rowXcolumn (scalar) value to be returned
by using a one-line function call (instead of $results =  and then  $row['fieldname'] =  the value you want)

with mysqli it is returning the error shown at the bottom.

any help with what was not updated properly for mysqli conventions?
thanks!


ex usage:  
      $NumLineItems = db_sql("SELECT COUNT(*) FROM tblSales_order_details WHERE so_header_key = 30 ");
        echo $NumLineItems;

definition
function db_sfq ($query)
{
      $result = db_sql($query);   // this function works fine
      if ($result)
        {
            $row      = mysqli_fetch_array($result);
            return $row[0]; // only one field scalar was requested
      }
}// end db_SingleFieldQuery

error
Catchable fatal error: Object of class mysqli_result could not be converted to string
MySQL Server

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon