We help IT Professionals succeed at work.

mysql -> mysqli  utility function conversion to work with mysqli

willsherwood
willsherwood asked
on
223 Views
Last Modified: 2015-02-14
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
Comment
Watch Question

Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
your comment helped lead to a stupid typo,  sorry for the trouble, and thanks for the info!

Author

Commented:
thanks for your help!  (as always, you're a GREAT resource!)
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
You're welcome, glad to help.