Solved

Getting error that does not match code

Posted on 2016-07-21
6
35 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 82

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 30

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 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

19 Experts available now in Live!

Get 1:1 Help Now