scottybwoy Posted May 15, 2007 Share Posted May 15, 2007 Small Question I have a little function that gets a result from a query when supplied arguments, it works great except when the result is 0. Here's the func : <?php function selectRecord($record, $tbl, $where, $val) { $sql = "SELECT $record FROM $tbl WHERE $where = $val"; $qry = mssql_query($sql); $res = mssql_result($qry, 0, 0) or trigger_error("There was an error selecting $record for $val", E_USER_ERROR); return $res; } ?> When ever it tries to return a 0 it triggers the SQL error. Any one know why? Quote Link to comment https://forums.phpfreaks.com/topic/51463-return-0/ Share on other sites More sharing options...
scottybwoy Posted May 15, 2007 Author Share Posted May 15, 2007 Now if I run an echo $sql and put that value in MSSQL query editor it returns the value 0 fine, now why does PHP throw up an error? Also if the value is anything else it will execute and return the result. Quote Link to comment https://forums.phpfreaks.com/topic/51463-return-0/#findComment-253504 Share on other sites More sharing options...
Daniel0 Posted May 15, 2007 Share Posted May 15, 2007 What do you mean with returning 0? What is the SQL error? Quote Link to comment https://forums.phpfreaks.com/topic/51463-return-0/#findComment-253530 Share on other sites More sharing options...
Dragen Posted May 15, 2007 Share Posted May 15, 2007 sorry.. I know this has nothing to do with the post but Daniel, can I just congratulate you on your sig php code! I just thought it was so funny when I realised what it did. Quote Link to comment https://forums.phpfreaks.com/topic/51463-return-0/#findComment-253534 Share on other sites More sharing options...
scottybwoy Posted May 15, 2007 Author Share Posted May 15, 2007 Hi Daniel, I mean that the result in the database is a 0, when I call via a SELECT Query, It fails and triggers the Defined error in my code. It works fine when the result in the database is not 0. When entering the same SELECT query directly into MsSQL it reters the 0 as expected. It seems as if the error is not with the php or MsSQL but the way they communicate with each other. Quote Link to comment https://forums.phpfreaks.com/topic/51463-return-0/#findComment-253651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.