Page 1 of 1

sql query problems

PostPosted: Mon Oct 12, 2009 3:34 pm
by entr04y
Hi all,

Having a problem with a sql query in an action:

This works:

$sql = "select mayor_name,city_name from cityinfo where county_name = 'some-county'";

This doesn't:

$sql = "select mayor_name,city_name,(round(sqrt((pow(( $x_pos - x_pos ),2) + (pow(( $y_pos - y_pos),2))))) as Distance from cityinfo where county_name = 'some-county'";

The error I get is:

[12-Oct-2009 18:37:25] PHP Fatal error: Call to a member function db() on a non-object in /ebs01/html/Salient/actions/neighbors.php on line 15


Any idea what is wrong with the above query? It executes as expected when cut and pasted directly into a mysql prompt (the only difference being $x_pos and $y_pos are changed to actual values in the mysql prompt.)

Thanks!

PostPosted: Wed Oct 14, 2009 12:03 pm
by shannah
Before passing $sql into your query, echo the $sql and see what it says. Then you can put this sql directly into phpmyadmin and find out where the problem is (although it will probably be obvious by eyeballing it).

You might also try doing some error reporting because mysql will tell you want the problem is .

e.g.
$res = mysql_query($sql, df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()));