Jump to content

Recommended Posts

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();

?>

Link to comment
https://forums.phpfreaks.com/topic/84385-ms-sql-calls-within-function/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.