# Function Trouble

**URL:** <https://www.phphelp.com/t/function-trouble/31883>\
**Category:** Beginners - Learning PHP\
**Created:** [May 18, 2020, 6:51am UTC](https://www.phphelp.com/t/function-trouble/31883 "2020-05-18T06:51:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveJawns](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@SteveJawns](https://www.phphelp.com/u/SteveJawns)\
**Post date:** [May 18, 2020, 6:51am UTC](https://www.phphelp.com/t/function-trouble/31883/1 "2020-05-18T06:51:10Z")

</div>

I’m having trouble with a function I’m trying to have a function where it displays a notification for the user whenever a new update is posted but whenever I call the function I get this error " **Fatal error** : Uncaught Error: Call to undefined method mysqli\_stmt::fetch\_array() in /home/evoarena/public\_html/Dev/functions.php:67 Stack trace: #0 /home/evoarena/public\_html/Dev/header.php(140): notifications(Object(mysqli)) #1 /home/evoarena/public\_html/Dev/login.php(3): require(‘/home/evoarena/…’) #2 {main} thrown in **/home/evoarena/public\_html/Dev/functions.php** on line **67**"

What am I doing wrong\>  
Line 67 is

> $news\_user = $news\_stmt-\>fetch\_array();

Function Code:

```auto
function notifications($link) {
 if (isset($_SESSION['username'])) {
  $username = $_SESSION['username'];
    $news_query = "SELECT news_read FROM users where username=?";
    if ($news_stmt = $link->prepare($news_query)) {    
      $news_stmt->bind_param("s", $username);
      $news_stmt->execute();
      $news_result = $news_stmt->get_result();
      $news_user = $news_stmt->fetch_array();      
      if ($news_user['news_read'] == '0') {      
          echo "<div class='alert alert-primary alert-dismissible' role='alert'>
        <center><button type='button' class='close' data-dismiss='alert'>&times;</button>There is a new post on the <a href='http://www.pereia.net/Dev/news/index.php'>Updates</a> page
        </center></div>";      
      }      
    } else {    
       $error = $link->errno . ' ' . $link->error;
       echo $error;
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [May 18, 2020, 8:26am UTC](https://www.phphelp.com/t/function-trouble/31883/2 "2020-05-18T08:26:38Z")

</div>

The following link is to the mysqli\_stmt documentation - [https://www.php.net/mysqli\_stmt](https://www.php.net/mysqli_stmt)

Yep. The error message is correct. There is no mysqli\_stmt method named fetch\_array().

It does have a fetch() method, requiring that you use the bind\_result() method first and it has a get\_result() method, which only exists in a specific server configuration and shouldn’t be used unless you manage your own servers.

Since you are using the get\_result() method, you end up with a mysqli\_result object in **$news\_result** , which does have a fetch\_array() method. Perhaps proof-read your code to make sure of what variable is being used.

If you switch to the much simpler and more consistent PDO extension, several of those lines of code will go away. You will only have a prepare(), execute(), and fetch() statement.

---

<div class="post-metadata">

**Author:** ![SteveJawns](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@SteveJawns](https://www.phphelp.com/u/SteveJawns)\
**Post date:** [May 18, 2020, 8:38am UTC](https://www.phphelp.com/t/function-trouble/31883/3 "2020-05-18T08:38:24Z")

</div>

I have used fetch\_array in other queries and it has never given me an error before

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [May 18, 2020, 10:46am UTC](https://www.phphelp.com/t/function-trouble/31883/4 "2020-05-18T10:46:31Z")

</div>

I think you missed something in phdr’s comment.

> [@phdr](#):
>
> Since you are using the get\_result() method, you end up with a mysqli\_result object in **$news\_result** , which does have a fetch\_array() method. Perhaps proof-read your code to make sure of what variable is being used.
