Home php Why does not work mysqli_query () and mysqli_fetch_all ()

Why does not work mysqli_query () and mysqli_fetch_all ()

Author

Date

Category

source https: // www. YouTube.com/watch?v=z_5RGO38CDC&amp ;list=llhgpabr2inepdgxhiaptdsq&Index=5&amp ;t=962s
The code looks like this

& lt;? php
   $ mysqli = new mysqli ('localhost', '...', '...', '...');
  if (! $ mysqli) {
    DIE ("ConnAction Failed" .mysqli_connect_error ());
  }
  FUNCTION Get_Posts () {
    Global $ Musqli;
    $ SQL = "SELECT * FROM POSTS";
  "Line6" $ result = mysqli_query ($ Musqli, $ SQL);
  "Line7" $ posts = mysqli_fetch_all ($ result, mysqli_assoc);
    Return $ posts;
  }
          & lt; pre & gt; & lt;? PHP VAR_DUMP ($ Posts)? & GT; & lt; / pre & gt;
        & lt;? php
        $ posts = get_posts ();
         ? & gt;
    "Line 78" & lt;? PHP Foreach ($ Posts as $ Post) :? & gt;
         Div in which settings are substituted
        & lt;? php endforeach; ? & gt;

Warning error: mysqli_query () EXPECTS PARAMETER 1 TO BE MYSQLI, NULL GIVEN IN D: \ OpenServer \ Ospanel \ Domains \ Project2 \ index.php on line 6

warning: mysqli_fetch_all () EXPECTS PARAMETER 1 TO BE MYSQLI_RESULT, NULL GIVEN IN D: \ OpenServer \ OSPanel \ Domains \ Project2 \ index.php on line 7

Warning: Invalid Argument Supplied for Foreach () In D: \ OpenServer \ Ospanel \ Domains \ Project2 \ index.php on line 78


Answer 1, Authority 100%

Init databases in the “OOP”, and variable “procedural”.

In the OOP variable has the type of object: $ mysqli- & gt; query ();

In the procedural: mysqli_query ($ link, $ query); , where, for example, $ Link = mysqli_connect ();

It will be useful: https://www.php.net/manual/ RU / mysqli.Query.php

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions