What defines the PHP error: Call to a member function fetch_object() on a non-object -


I was thinking this question for a while. I have two PHP programs that are almost exactly the same, except for the fact that one of them is function and the other is not. In addition, one works and returns the second error:

  Call fetch_object () on a non-object member function  

I decided Is to leave the variable and insert a fixed string and replace mysqli_errno instead of $ con- & gt; Errno was not working by adding However, when I changed the wire again with the variable, then the problem returned

So, my question is: What is the cause of this error and How do I fix this? Besides, why is the error in the second code and not the first?

The first code (action)

   fetch_object (); $ coordinator = $ result_row-> ; Coordinator; $ declaration = $ result_row-> announcements; $ description = $ result_row-> description; $ Comments = $ result_row-> comments; $ painting = $ result_row-> pictures; mysqli_error ($ Thor); mysqli_close ($ thief); if ($ picturespath == "") {$ photopath = "../images/AlumnLogo.png";}? & Gt;  

< Strong> second code (does not work)

  & lt; php function fetch ($ page, $ content1, $ content2, $ content3) {$ con = new mysqli (" Data Es info "); if ($ con- & gt; wrong) {echo" MySQL failed to join: ". Mysqli_connect_error ();} $ Stmt = $ con- & gt; query (" SELECT "" $ content1. " '', ''. $ Content2. "','". $ Content3. "'FROM'". $ Page. "';'); $ Result_row = $ stmt-> Fetch_object (); $ Content = array (); $ Content [0] = $ result_row- & gt; the body; $ Content [1] = $ result_row- & gt; Calendar; $ Content [2] = $ result_row- & gt; Announcements; $ Output = intestine ("-", $ contents); Mysqli_error ($ thief); Mysqli_close ($ thief); Return $ output; }? & Gt;  

Thanks a lot!

You are quoting your column names using a single quote. You can not do this, you need to quote table- and column names using the backticks (in the case of reserved words, spaces, etc.) and only (non-integer ...) values. Need to be quoted using single or double quotation marks. / P>

Change your code to:

  $ stmt = $ con- & gt; Query ("Select". $ Content1. "`, `" $ Content2. "`, `` $ Content3. '`` `.page page." `;"); ^ All these  

Anyway, I believe that you are using a white list for your table - and the column name If not, you should avoid SQL injection.

It is also a good idea to add error to your database calls. An easy way to use MySqli, at the beginning of your script, mysqli_report (MYSQLI_REPORT_STRICT); is inserted, it will give reasons for throwing an exception to MySky, so that you do not check personal errors on every database call.


Comments