bengaltgrs Posted January 3, 2008 Share Posted January 3, 2008 I'm trying to put a sql call within a function, but it does not work. If I comment out the function and just run the code straight as it is in the code below however, it works just fine. Why doesn't this code work when within a function? <?php $db = new COM("ADODB.Connection"); $dsn = "DRIVER={SQL Server}; SERVER={localhost};UID={user};PWD={pass}; DATABASE={db_name}"; $db->Open($dsn); //function GetMemberIDCreateIfNew($username, $is_admin) //{ echo "getting member id<br>"; $strquery = "SELECT member_id FROM members WHERE screen_name = 'sdasdawasdawda'"; $rs = $db->Execute($strquery); $new_member_id = ""; if(!$rs->EOF) { $new_member_id = $rs->Fields['member_id']->Value; } else { $strquery = "SELECT NewID() AS my_id"; $rs = $db->Execute($strquery); $new_member_id = $rs->Fields['my_id']->Value; } $ret_member_id = $new_member_id; echo $ret_member_id; // return $ret_member_id; //} //GetMemberIDCreateIfNew("sdasdawasdawda", "false"); $db->Close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/84385-ms-sql-calls-within-function/ 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.