Solved

mysql -> mysqli  utility function conversion to work with mysqli

Posted on 2014-11-11
4
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

627 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