PHP? Method? MySQL

Source: Internet
Author: User
PHP? Method? New to mySQL
Recently? ? I? Search? Program
Mainly using php? Media ?? Android and mySQL
No ?? Stuck in my php? Legal success? SQL? Method
Which of the following are my main tasks ?? Program snippet:
(In java)
Try {
String result = DBConnector.exe cuteQuery ("SELECT * FROM user where zip = 'newzip '");
System. out. println (result );

(Php? Method)
$ Db = mysql_pconnect ("localhost", "root", "1234 ");

Mysql_query ("set character set 'utf8 ';");
Mysql_query ("set names UTF8 ;");
Mysql_query ("SET CHARACTER_SET_CLIENT = UTF8 ;");
Mysql_query ("SET CHARACTER_SET_RESULTS = UTF8 ;");
Mysql_select_db ("food ");

$ SQL = $ _ POST ["query_string"];

$ Res = mysql_query ($ SQL );
While ($ r = mysql_fetch_assoc ($ res ))
$ Output [] = $ r;

Print (json_encode ($ output ));
Mysql_close ();
?>

? It's my ??? Information:
Mysql_fetch_assoc (): supplied argument is not a valid MySQL result resource in C: \ AppServ \ www \ AndroidConnectDB \ android_connect_db.phpOn line 13

I have? In java? Method directly in phpmyadmin? Line
(SELECT * FROM user where zip = 'newzip ')
Yes. OK? Find ?? Yes? Parts? Raw materials
But I don't know? What? Transparent? Java? Call mySQL in php? OK ??? Yes? Back ??
Upper? Crawling? Many articles
Yes? Are you correcting ??? ?? (Set names UTF8 ;)
Are there any changes to php. ini? Magic_quotes_gpc = On
But still? ? Null and ??? Information
But me? It is changed
SELECT * FROM user where id = 1?
Yes. OK ?? 00 of the row"
So I guess? No? Yes? Introduction? Cause ??
Yes, too? It is changed
SELECT * FROM user where zip =/'newzip /'
? Still? No? OK ???

Yes ?? Do you have any solutions? Method ???


Reply to discussion (solution)

It is useless to guess. you need to see the error message when an error occurs.
$ Res = mysql_query ($ SQL) or die (mysql_error ());
Because the error message you provided is
Mysql_fetch_assoc (): supplied argument is not a valid MySQL result resource
That is, the MySQL resource passed to mysql_fetch_assoc is not a valid MySQL resource.

? Hello, eldest brother!> <
My mtsql_error? Description:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\ 'newzip \ ''at line 1
So? Is it my character? There are ????
What should we do ?? Is it positive? ?
I have ??? It is changed to SELECT * FROM user where zip = \ 'newzip \'
But I ?????

Shouldn't you think so?

SELECT * FROM user where zip = 'newzip'

I have ????? Now
But ?? Show 1? ?? @@
SELECT * FROM user where id = 1
?? Can it be normal? Line
But if it is changed to another one? ? Expected? Not good ??

Disable magic quotes and modify php. ini magic_quotes_gpc = Off.
Or temporarily reverse the meaning of the input string

$sql = stripslashes($_POST["query_string"]);
It can also be handled.

Disable magic quotes and modify php. ini magic_quotes_gpc = Off.
Or temporarily reverse the definition of PHP code for the input string? 1 $ SQL = stripslashes ($ _ POST ["query_string "]);
?? !! It can be captured successfully :)

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.