PHP? into MySQL

Source: Internet
Author: User
Little sister is a novice PHP
You want to do it recently?
Mainly by PHP as the media?? Android and MySQL
No?? Stuck in my php all the way to the successful award? SQL? method
The following is my main?? Program Fragment:
(in Java)
try {
String result = Dbconnector.executequery ("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???. Interest:
MYSQL_FETCH_ASSOC (): supplied argument is not a valid MySQL result resource in C:\AppServ\www\AndroidConnectDB\android_connect_db.phpOn line -

I have? The phpMyAdmin in Java is directly in the middle of the line.
(i.e. Select*from user where zip = ' newzip ')
Can you find it? Conforming to the parts of the material
But I don't know, what? into PHP to call MySQL???? What's the answer?
A lot of the paper.
To fix???. Of?? (SET NAMES UTF8;)
Have to go to php.ini modify? MAGIC_QUOTES_GPC = On
But still? null and??? Interest
But I? It changed to
Select*from user where id=1?
Is it possible to be positive? Row of 00 "
So guess again????
It's changed.
Select*from user where zip =/' newzip/'
It's still not good???

Want?? Do you have any solution???


Reply to discussion (solution)

Guessing is useless and you need to see the error message when the error occurs
$res = mysql_query ($sql) or Die (Mysql_error ());
Because the error message you gave is
MYSQL_FETCH_ASSOC (): supplied argument is not a valid MySQL result resource
That is not a valid MySQL resource that is passed to MYSQL_FETCH_ASSOC, so look up incrementally

? Hello ~!> <
My mtsql_error? Show:
You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near ' \ ' Newzip\ ' on line 1
So, is that my character? There are???? in the part
What's that supposed to be? What is the whole thing?
I have??? It changes to Select*from user where zip = \ ' Newzip\ '
But a?????

Don't you think that's the way it should be?

SELECT * from user where zip = ' newzip '

I have????? The
But?? A.?? @@
SELECT * FROM user where id = 1
?? Okay, OK?
But what if we change to a different person?

Turn off Magic quotes, modify php.ini MAGIC_QUOTES_GPC = Off
or temporarily invert the incoming string

$sql = Stripslashes ($_post["query_string"]);
You can handle it.

Turn off Magic quotes, modify php.ini MAGIC_QUOTES_GPC = Off
or temporarily invert the incoming string to PHP Code?1$sql = stripslashes ($_post["query_string"]); You can handle it.
Sense?? Bit BIG!! Can be successfully caught:)

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