Fatalerror: Calltoamemberfunctionfetch_array () onanon-object error

Source: Internet
Author: User
Fatalerror: Calltoamemberfunctionfetch_array () onanon-object error
include_once ('conn.php');//error_reporting(0);@$shops_name= $_GET["shops_name"];if (isset($shops_name)) {echo $shops_name;$query = "SELECT * FROM goods WHERE ShopName= '$shops_name'";@$q = $conn->query($query);while($row=$q->fetch_array()) {$select[]=array("goods_id"=>$row[ID],"goods_name"=>$row[Name]);}echo json_encode($select);}


Copy @ query to mysql for query success. However, the problem is solved.


Reply to discussion (solution)

Paste your conn. php

$ Conn = new mysqli ("localhost", "root", "zxfang", "test02 ");
If (! $ Conn ){
Die ("failed to connect to the database:". mysqli_connect_error ());
}

$ Conn-> query ("set character set 'gbk '");
$ Conn-> query ("set names 'gbk '");
?>

$ Q = $ conn-> query ($ query );
Echo $ q = $ conn-> error;

$ Q = $ conn-> query ($ query );
Echo $ q = $ conn-> error;



Illegal mix of collations (utf8_general_ci, IMPLICIT) and (gbk_chinese_ci, COERCIBLE) for operation '=

What does it mean ??

After modifying the table Field Encoding, there is no Illegal mix of collations (utf8_general_ci, IMPLICIT) and (gbk_chinese_ci, COERCIBLE) for operation '=, or Fatal error: Call to a member function fetch_array () on a non-object

@ $ Q = $ conn-> query ($ query );
Change
$ Q = $ conn-> query ($ query) or die ($ conn-> error );

Check for any error output.

It is estimated that your SQL execution is faulty.

@ $ Q = $ conn-> query ($ query );
Change
$ Q = $ conn-> query ($ query) or die ($ conn-> error );

Check for any error output.

It is estimated that your SQL execution is faulty.


The original table has
Illegal mix of collations (utf8_general_ci, IMPLICIT) and (gbk_chinese_ci, COERCIBLE) for operation '=' error.
After the table field encoding is changed to gbk, $ conn-error indicates that no error is returned, but there is still Fatal error: Call to a member function fetch_array () on a non-object.

Do not modify the character set of a table with data at will, because the modification of the character set does not modify the character set of the content at the same time.
Please switch back to the character set for salt to avoid data loss!

$ Query = "SELECT * FROM goods WHERE ShopName = '$ shops_name '";
After
Echo base64_encode ($ query );
Post the result (of course, when an error occurs)

Do not modify the character set of a table with data at will, because the modification of the character set does not modify the character set of the content at the same time.
Please switch back to the character set for salt to avoid data loss!

$ Query = "SELECT * FROM goods WHERE ShopName = '$ shops_name '";
After
Echo base64_encode ($ query );
Post the result (of course, when an error occurs)


U0VMRUNUICogRlJPTSBnb29kcyBXSEVSRSBTaG9wTmFtZT0gJ + W6lzEn

echo base64_decode('U0VMRUNUICogRlJPTSBnb29kcyBXSEVSRSBTaG9wTmFtZT0gJ+W6lzEn');

In the gbk environment: SELECT * FROM goods WHERE ShopName = 'batch? 1'
In UTF-8 environment: SELECT * FROM goods WHERE ShopName = 'shop 1'
Apparently, you passed in UTF-8 encoded data.
Do you still use gbk encoding ($ conn-> query ("set names 'gbk'");) to avoid errors?

Oh, it turns out that I have never been very familiar with coding.
Okay, the problem is solved. thank you, moderator.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.