Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

php - Pasted MySQL Select Statement Returns Empty Set, but Manual Select Works Fine

This one has 2 tech teams baffled.

I have an HTML form that submits to a PHP script that generates the following simple MySQL command:

SELECT * FROM table WHERE parameter='something';

The problem is, when I run the PHP script, I get an empty set returned. However, when I type the command into SQL manually, it works fine and returns rows as it should. The closest guess I can figure is, the pasted command has some sort of hidden characters in it ... ?

Any advice is greatly appreciated

EDIT:

exact PHP query: $query = mysql_query("SELECT * FROM Residential WHERE ".$parameters." ORDER BY 'Residential','list_price' ASC LIMIT ".$offset.", ".$listinglimit."; ") or die('Could not connect: ' . mysql_error()); echo'd query (which is also submitted to MySQL): SELECT * FROM Residential WHERE sub_area_name='TJ–Trojan' AND list_price <= 99999999 ORDER BY 'Residential','list_price' ASC LIMIT 0, 10; If I paste that query into phpmyadmin, the result is an empty set. But if I type it manually then the result is returned rows (as it should be)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Asuming you have inside your code something like

...
$query = "SELECT * FROM table WHERE parameter='$param'";
...

Just echo out the var $query to make sure it's indeed the same as the one you ran manually

echo $query;

In my opinion if it's the same, it can't fail just because it's executed via php.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...