Avatar of breeze351
breeze351
 asked on

Getting error that does not match code

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"?
PHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dave Baldwin

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
Marco Gasi

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

Ray Paseur

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
breeze351

ASKER
Sometimes I'm a moron.  Changed it to fetch_array() and it worked.  Stared at this all afternoon!!!
Thanks
Ray Paseur

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()