以下代码未使用 mysql_query() 函数按预期工作。
$conn = mysql_connect('localhost','user','pass') or die (mysql_error());
mysql_select_db('db') or die (mysql_error());
$sql = "SET @orig_lat=33.81978250;SET @orig_lon=-118.10641560; SET @dist =10;SELECT Name, Address, City, State, Zip, 3956 *2 * ASIN( SQRT( POWER( SIN( ( @orig_lat - abs( b.lat ) ) * pi( ) /180 /2 ) , 2 ) + COS( @orig_lat * pi( ) /180 ) * COS( abs( b.lat ) * pi( ) /180 ) * POWER( SIN( ( @orig_lon - b.lng) * pi( ) /180 /2 ) , 2 ) ) ) AS distance FROM tblDealer AS b HAVING distance < @dist ORDER BY distance LIMIT 10";
$result = mysql_query($sql, $conn) or die (mysql_error());
$num_rows = mysql_num_rows($result) or die (mysql_error());
echo $num_rows;
这在 phpMyAdmin 中运行得很好。谁能告诉我出了什么问题吗?
当我尝试运行它时,出现以下错误:
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 'SET @orig_lon=-118.10641560; SET @dist =10;SELECT Name, Address, City, State, Zi' at line 1
最佳答案
mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
如何克服这个问题?使用mysqli extension相反。
关于mysql_query() 没有按预期工作,但 phpmyadmin 是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12850811/