Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mysql -> mysqli  utility function conversion to work with mysqli

Posted on 2014-11-11
4
Medium Priority
?
189 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 84

Expert Comment

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

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

963 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