[Serious when going in] the prompt "Warning: mysql_fetch_array (): suppliedargumentisnotavalidMySQLresult" is displayed when retrieving data from mysql.

Source: Internet
Author: User
[Serious when I come in] the prompt "Warning: mysql_fetch_array (): suppliedargumentisnotavalidMySQLresult" is displayed when I fetch data from mysql. this is a question that I have hundreds of times and google has queried countless times, probably because the SQL query, the data cannot be found. One of them, what do you say? I feel that this person is deliberately misleading others and telling others everywhere that the prompt "Warning: mysql_fetch_array ()" is prompted when retrieving data from mysql in mysql_f [Please be serious (): supplied argument is not a valid MySQL result
For example, this problem is caused by hundreds of times of queries made by google, which is due to incorrect SQL query statements and data not found. One of them, how can we say that this person is deliberately misleading others and telling others everywhere to add @ to mysql_fetch_array to block error information? in fact, the problem has not been solved, just because no error is prompted. Below is the code

$ Conn = mysql_connect ("localhost", "test", "test ");
Echo $ conn ."
"; // The printed result here is: Resource id #1
Mysql_select_db ("test ")
$ R = mysql_query ("select * from table1 where id> 0", $ conn );
If ($ r = false) echo "query error"; // The result is query error.
Else
{
While ($ row = mysql_fetch_array ($ r, MYSQL_ASSOC ))
{
$ Rows [] = $ row;
}
}
In fact, I can run this program locally. it won't work if it can be uploaded to the houstmonster virtual machine. for debugging, I simplified the program to the above, but it still won't work, after the query is executed, false is always returned. an error is returned when data is retrieved. Warning: mysql_fetch_array (): supplied argument is not a valid MySQL result

I connected the server using phpMyadmin and executed select * from table1 where id> 0.
Please give me some advice. I'm a beginner in php and transferred it from c.

------ Solution --------------------
$ R = mysql_query ("select * from table1 where id> 0", $ conn );
Have you reversed the statement: $ r = mysql_query ($ conn, "select * from table1 where id> 0 ");

While ($ row = mysql_fetch_array ($ r, MYSQL_ASSOC ))
MYSQL_ASSOC? Do you need this? Direct while ($ row = mysql_fetch_array ($ r) is not acceptable? Why is your writing method different from mine ~~~~
------ Solution --------------------
It is recommended that you read the manual and read the manual. you can solve most of the problems by yourself.
------ Solution --------------------
To upload data to the server, you need to change the user name and password.


PHP code
$ Conn = mysql_connect ("localhost", "test", "test") or die ('connection failed '); mysql_select_db ("test "); // note the semicolon $ r = mysql_query ("select * from table1 where id> 0", $ conn) or die ("query failed "); if (mysql_num_rows ($ r)> 0) {// if there is a record, execute while ($ row = mysql_fetch_array ($ r )) {$ rows [] = $ row ['field'];}
------ Solution --------------------
Discussion
$ R = mysql_query ("select * from table1 where id> 0", $ conn );
Have you reversed the statement: $ r = mysql_query ($ conn, "select * from table1 where id> 0 ");

While ($ row = mysql_fetch_array ($ r, MYSQL_ASSOC ))
MYSQL_ASSOC? Do you need this? Direct while ($ row = mysql_fetch_array ($ r) is not acceptable? Why is your writing method different from mine ~~~~

------ Solution --------------------
MYSQL_ASSOC should return rows as management arrays, field names represent keys, and field content represents values. The landlord said that you performed an error in the space. Are you sure you have no problems with the database configuration?
In addition, I usually use the mysqli extension for operations. Is mysql_fetch_array php4 written? Mysql_fetch_array ($ query );
------ Solution --------------------
I used to encounter @ errors, but I later found out. If you want to add, add all or none. An error is reported when two values are added.
The code on the fifth floor has been clearly written. Lz, read the manual more.

------ Solution --------------------
The returned array is false.
In this case, I once met, but someone else said access.
We recommend that you check whether the mysql version on the server and the local database is consistent with the database creation statement.
While ($ row = mysql_fetch_array ($ r, MYSQL_ASSOC ))
The problem may be the parameter MYSQL_ASSOC you added. In fact, you directly $ row = mysql_fetch_array ($ r). by default, both numeric indexes and field indexes exist, then, print_r ($ row) is used to check whether the server supports field name index.

------ Solution --------------------
Discussion
The returned array is false.
In this case, I once met, but someone else said access.
We recommend that you check whether the mysql version on the server and the local database is consistent with the database creation statement.
While ($ row = mysql_fetch_array ($ r, MYSQL_ASSOC ))
The problem may be the parameter MYSQL_ASSOC you added. In fact, you directly $ row = mysql_fetch_array ($ r). by default, both numeric indexes and field indexes exist, then, print_r ($ row) is used to check whether the server supports field name index.


------ Solution --------------------
Haha, you may never believe it when you don't have any problems. After debugging, you will know why!
------ Solution --------------------
Discussion

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.