"Go in, please be serious." Prompt Warning:mysql_fetch_array () when fetching data from MySQL: supplied argument is not a valid MySQL result

Source: Internet
Author: User
"Come in, please be serious." Prompt Warning:mysql_fetch_array () when fetching data from MySQL: supplied argument is not a valid MySQL result
Title, this question I on Baidu, Google query countless, how much is because SQL query statement error, can not find data caused. One of them, how to say, feel this person deliberately mislead others, everywhere tell others in Mysql_fetch_array add a @ To block the error message, in fact, the problem is not solved, just do not prompt the wrong only. Here is the code

$conn =mysql_connect ("localhost", "Test", "test");
echo $conn. "
";//The result is printed here: Resource ID #1
mysql_select_db ("Test")
$r =mysql_query ("select * FROM table1 where ID > 0", $conn);
if ($r ==false) echo "Query error";//This prints the result: query error
Else
{
while ($row =mysql_fetch_array ($r, MYSQL_ASSOC))
{
$rows []= $row;
}
}
In fact, this program, I can be run locally, can be uploaded to Houstmonster virtual machine on the die, for debugging, I simplified the program to the above look, can still not, execute query query, always return FALSE, fetch data error, WARNING:MYSQL_ Fetch_array (): supplied argument is not a valid MySQL result

I use phpMyAdmin to connect to the server and execute select * FROM table1 where ID > 0 is no problem.
Please expert guidance, I was a beginner php, from C # turned around.

------Solution--------------------
$r =mysql_query ("select * FROM table1 where ID > 0", $conn);
Did you write the inverse: $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)) can't you? Why your writing is not the same as mine ~ ~ ~
------Solution--------------------
It is recommended to read more manuals, learn to read manuals, most of the problems can be done by themselves.
------Solution--------------------
Upload to server to change user name and password


PHP Code
$conn =mysql_connect ("localhost", "Test", "test") or Die (' join unsuccessful ');   mysql_select_db ("test"); Note the semicolon $r=mysql_query ("select * FROM table1 where ID > 0", $conn) or Die ("Query unsuccessful");      if (mysql_num_rows ($r) >0) {//If there is a record then execute while ($row =mysql_fetch_array ($r)) {$rows []= $row [' field ']; } }
------Solution--------------------
discuss
$r =mysql_query ("select * FROM table1 where ID > 0", $conn);
Did you write the inverse: $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)) can't you? Why your writing is not the same as mine ~ ~ ~

------Solution--------------------
Mysql_assoc, the row should be returned as an administrative array, the field name represents the key, and the field content represents the value. Landlord said, you are in the space to execute the error, you are sure you are in the configuration of the database there is no problem?
In addition I usually use the mysqli extension to operate. Mysql_fetch_array is not the php4 of the wording ah? Mysql_fetch_array ($query);
------Solution--------------------
I've also had errors with add @, but I found out later. If you want to add all the add, or all of them do not add. Add individual two will be error.
The code on the 5 floor has been written very clearly. LZ, look at the handbook.

------Solution--------------------
Returns an array of false
I have encountered this situation once, but others say access.
It is recommended to check the server and the local MySQL version, as well as the build database statements are consistent.
while ($row =mysql_fetch_array ($r, MYSQL_ASSOC))
The problem may be that you add to which parameter MYSQL_ASSOC, in fact you directly $row=mysql_fetch_array ($R), the default is both numeric index and field index are present, and then Print_r ($row) to see if the server supports the field name index.

------Solution--------------------
Explore
Returns an array of false
I have encountered this situation once, but others say access.
It is recommended to check the server and the local MySQL version, as well as the build database statements are consistent.
while ($row =mysql_fetch_array ($r, MYSQL_ASSOC))
The problem may be that you add to which parameter MYSQL_ASSOC, in fact you directly $row=mysql_fetch_array ($R), the default is both numeric index and field index are present, and then Print_r ($row) to see if the server supports the field name index.


------Solution--------------------
Oh, no problem when you may never believe, debugging a bit to know why!
------Solution--------------------
discuss
  • Related Article

    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.