Custom External functions page

I am running into issues with using an external functions page.
Since Scriptcase insists on attaching ALL of the functions in an included internal libraries page, I needed to just use basic php include page functionality.
However, the connections I have set up aren’t being recognized.
Has anyone been able to accomplish this?

If by using an include you’re in the same situation as when using external libraries (i.e. no access to SC macros and variables) maybe what I do in that case could help you.

in the app i call the external library function passing to it the db connection object ($this->Db)
E.g.

$o_db = $this->Db;
$id = 522;
$field_value = get_db_value($o_db, $id);

In the external library i use standard syntax to use the connection (in my case is adodb, if your SC db connections use something different I guess you’ll have to adjust the syntax).
Eg.:

function get_db_value($o_db, $id)
{
 	$sql = "SELECT field_name FROM table_name WHERE id_field=$id";
 	$rs = $o_db->Execute($sql);
 	if (false == $rs) 
    {
 	    // error handling code
 	}  
    else 
    {
 	    $r = $rs->fields[0];
 	    $rs->Close();
 	}
 	return $r;
}

Thanks so much!! That was very helpful.

Btw, if you don’t want to republish all apps using the same external function when you update that function, why don’t you use SC external libraries?

Especially if with a manual include you end up with no access to SC variables/macros anyway.

With external libraries you can still manage and publish your external functions using SC.

1 Like

Do SC macros work on an external library page?

Nope.

But I was under the impression that by using an include you were in the same situation, because you wrote that you couldn’t access the SC connection from the included file.

Ya… same situation. The Internal libraries are stupid in SC.
So I have my own set of Connection classes and functions to make an external functions page that I just include with regular old require ()