Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:53:26+00:00 2026-06-14T22:53:26+00:00

so my friend just changed my php so I’m using mysqli and after slight

  • 0

so my friend just changed my php so I’m using mysqli and after slight modifications to my code I still receive:
Fatal error: Call to undefined method mysqli::fetch_object() in C:\wamp\www\web2\database.php on line 44

   <?php
class Database 
{ 
 public $server = "localhost";
 public $database = "database"; 
 public $user = "root"; 
 public $password = ""; 
 public $row;
 public $result;
 public $sqlExtra = " ORDER BY firstname ASC";
 public $dbLocalHost;





 //call connection method upon constructing 
 public function __construct(){
  $this->createConnection(); 
 }

 //connection to the database
 public function createConnection() 
    { 
     $this->dbLocalhost = new mysqli($this->server, $this->user, $this->password, $this->database)
                or die("could not connect:");


      //mysql_select_db($this->database)
       //
       //  or die("Could not find the database: ".mysql_error());



 } 

 //execute query string 
 public function query($queryString) 
    {


        $result = $this->dbLocalhost->query($queryString);

        while($row = $this->dbLocalhost->fetch_object($result))
        {
            echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
        }

    } 

    public function newRecord($fname, $lname)
    {
        $firstname = $fname;
        $lastname = $lname;

        $this->emptyCheck($firstname, $lastname);
        $this->insert($firstname, $lastname);
    }

    function insert($fname, $lname)
    {
        $insert = "INSERT INTO table (firstname, lastname)
            VALUES ('$fname','$lname')";
        mysql_query($insert)
        or die("could not insert:".mysql_error());
        header('Location: blah.php');

    }

    function emptyCheck($fname, $lname)
    {
        if ($fname == "" || $lname == "")
        {
            echo "Please fill in all the fields.";
        }
    }


} 

?>

and this page displays it:

  <?php

include('database.php');
$db = new Database();
$sql = "SELECT * 
    FROM tables"; 

if ($_GET['sort'] == 'id')
{
    $sql .= " ORDER BY id";
}
elseif ($_GET['sort'] == 'fn')
{
    $sql .= " ORDER BY firstname";
}
elseif ($_GET['sort'] == 'ln')
{
    $sql .= " ORDER BY lastname";
}






?>

<html>
<body>


    <table>
  <tr>
    <td>

      <table border="1" align="center">
      <tr>
        <th><a href="blah.php?sort=id">ID</a></th>
        <th><a href="blah.php?sort=fn">First Name</a></th>
        <th><a href="blah.php?sort=ln">Last Name</a></th>
        <th>Edit</th>
        <th>Delete</th>
      </tr>
<?php
$db->query($sql);
?>
      </table>
</table>
    <a Href="new.php">Add new Record</a>

</body>
</html>

Sorry if this is really obvious, I’m terrible at webdev and new to mysqli.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:53:27+00:00Added an answer on June 14, 2026 at 10:53 pm

    You should use fetch_object on the result of the query and not on your database connection:

    $result = $this->dbLocalhost->query($queryString);
    
    while($row = $result->fetch_object())    // here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just had a friend of mine look over some code I'm using to
I've just started looking at PHP Frameworks after spending loads of wasted time doing
I have this code function check(){ $.get(friend.php, { id: friendid }, function(data){ //Do stuff
I've just recently learned about friend class concept in C++ (I've googled around for
I was just reading an update from a friend's project, mentioning the use of
I am just curious, I am writing some notes for a friend and am
My friend and I were discussing the other day which style of code is
I'm trying to understand whay i get an error on this code: (the error
May you can help me... many years ago my friend gave me php script
I have noticed one of my friend using this. <a href=# onclick=return Buy();>» <b

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.