Solved

mysql -> mysqli  utility function conversion to work with mysqli

Posted on 2014-11-11
4
168 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
0
Comment
Question by:willsherwood
  • 2
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40436577
That error message often indicates an error in the previous statement.  If everything is ok, your code should work.  Look at Example #2 on this page: http://php.net/manual/en/mysqli-result.fetch-array.php
0
 

Author Comment

by:willsherwood
ID: 40437444
your comment helped lead to a stupid typo,  sorry for the trouble, and thanks for the info!
0
 

Author Closing Comment

by:willsherwood
ID: 40610372
thanks for your help!  (as always, you're a GREAT resource!)
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40610386
You're welcome, glad to help.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question