PHP can't write MySQL
Little sister is a novice PHP
Want to try to write a search program recently
Mainly via PHP as a medium to connect Android and MySQL
But stuck in my php has been unable to successfully read the SQL method
Here are my main problem program fragments:
(in Java)
try {
String result = Dbconnector.executequery ("Select*from user where zip = ' newzip '");
SYSTEM.OUT.PRINTLN (result);
(Php language 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 ();
?>
This is my bug message:
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 language in Java directly in the phpMyAdmin.
(i.e. Select*from user where zip = ' newzip ')
is to be able to find the correct item
But I don't know why it's always wrong to call MySQL when Java is written into PHP.
The internet crawled through a lot of text
have tried to fix the problem (SET NAMES UTF8;)
There are also go php.ini modified MAGIC_QUOTES_GPC = On
But still old, null and wrong messages
But I changed it to
Select*from User where id=1
is 00 "that can be done correctly
So guess it's not going to be a problem with a single primer.
and change it into a
Select*from user where zip =/' newzip/'
But I still don't see the ˊˋ.
Would you like to ask if there is a way to solve this problem? ˊˋ
------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
------Solution--------------------
Don't you think that's the way it should be?
SELECT * from user where zip = ' newzip '
------Solution--------------------
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.