Solved

Getting error that does not match code

Posted on 2016-07-21
6
37 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
6 Comments
 
LVL 142

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now