Solved

Getting error that does not match code

Posted on 2016-07-21
6
42 Views
Last Modified: 2016-07-21
Here is the code from the page:

      echo "fred";
      $SqlString1 = "SELECT * FROM survey_data WHERE SEQ like \"".$strt."%\" and CITY != \"\" and STAT != \"\" and ZIP != \"\"";
      $survey_data = $conn->query($SqlString1);
      $row_survey_data = $survey_data->fetch();

This is the display from the page:
fred
Fatal error: Call to undefined method mysqli_result::fetch() in /home/langsyst/public_html/Lansco/Update_Building.php on line 54

Line 54 is the $row_survey_data fetch

Where the hell is it getting "mysqli"?
0
Comment
Question by:breeze351
[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
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 41723621
the connection object you are using is using mysqli under the hood
hence, you need to use fetch_row or fetch_all
http://php.net/manual/en/class.mysqli-result.php
1
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41723622
That often means your query above it did not succeed.  'mysqli_result::fetch' is the name of the actual function used by fetch() with the 'mysqli' driver.  http://php.net/manual/en/mysqli-stmt.fetch.php
1
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41723633
That error is the often the signal taht the query fails: try to run the query in phpMyAdmin (or equivalent) and see what's happen.
 Also you should use mysqli_error( $conn ); to get the error:
      echo "fred";
      $SqlString1 = "SELECT * FROM survey_data WHERE SEQ like \"".$strt."%\" and CITY != \"\" and STAT != \"\" and ZIP != \"\"";
      echo $SqlString1 . '<br>';
      $survey_data = $conn->query($SqlString1);
      if ($survey_data){
           $row_survey_data = $survey_data->fetch();
     }else{
         echo mysqli_error( $conn );
     }

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41723634
How to use the MySQL extensions, including:
  1. Conversion from MySQL to modern extensions
  2. How to test for query success or failure and visualize any errors
  3. How to retrieve results
  4. How to avoid trip-wires such as mixing procedural and object-oriented code
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

The article includes tested-and-working code examples you can copy for your own use.
0
 

Author Closing Comment

by:breeze351
ID: 41723659
Sometimes I'm a moron.  Changed it to fetch_array() and it worked.  Stared at this all afternoon!!!
Thanks
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41723672
Fetch_Array() is an anti-pattern.  Unless you deliberately tell it otherwise, It returns twice as much information as needed, making it the least efficient way to acquire information from the results set.

in my experience, the best function (correct amount of data, easy-to-use syntax) is Fetch_Object()
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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