Asking for help, about MySQL.

Source: Internet
Author: User
PHP MySQL

This code has been engaged for an afternoon, ask the great God to see if the code has a problem
Tested to properly connect the database is the while loop condition $row = mysql_fetch_array ($result) This sentence returns false
The SQL query statements in the code are also correct in the Navcat, and there are more than 30 return results, please.

The code is as follows:
$con = mysql_connect ($dbhost, $dbuser, $dbpass); if ($con) {mysql_select_db ($dbname, $con); $result = mysql_query ("select * from Zzbus WHERE line_name= ' 58-way ', $con); while ( $row = mysql_fetch_array ($result)) {echo ($row [0];}}


Reply to discussion (solution)

Could be line_name= ' 58-way ' not set
It could also be that the encoding causes line_name= ' 58-way ' not established

Add:
The SQL statements are correct and copied to the Navcat to get the correct results
There is only this query operation in the entire code, no other action:

This code has been engaged for an afternoon, ask the great God to see if the code has a problem
Tested to properly connect the database is the while loop condition $row = mysql_fetch_array ($result) This sentence returns false
The SQL query statements in the code are also correct in the Navcat, and there are more than 30 return results, please.

The code is as follows:

$con = mysql_connect ($dbhost, $dbuser, $dbpass); if ($con) {mysql_select_db ($dbname, $con); $result = mysql_query ("select * from Zzbus WHERE line_name= ' 58-way ', $con); while ( $row = mysql_fetch_array ($result)) {echo ($row [0];}}

Add:
The SQL statements are correct and copied to the Navcat to get the correct results
There is only this query operation in the entire code, no other action:

That could be the coding problem, what code your table is, plus one sentence: mysql_query ("Set names ' Your table code '");

1) Use Mysql_error to see if there are any errors
2) Remove Chinese characters and look at the results

Problem with coding
There are 3 things to agree on:
1, page encoding xxx

2, Encoding of PHP files (ANSI or UTF8)
3, MySQL client encoding (set names XXX)

If the encoding of the Web page is GBK, then PHP file encoding is ANSI, each MySQL connection will have to send a set names GBK (if the server encoding is also GBK, set names XXX This statement can be exempted)


1) Use Mysql_error to see if there are any errors
2) Remove Chinese characters and look at the results
1) return null value with Mysql_error (), should be no error message
2) Remove the "road" behind the 58.
Now the suspicion should be mysql_fetch_array ($result) This sentence is not working properly

Thanks to the Great God Guide ~ ~ ~
The problem is solved, it's the coding problem.
Precede the query with this sentence mysql_query ("Set names ' UTF8"); All problems solved
I really appreciate it.

  • 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.