i have a class:
class Connect
{
public function auth()
{
... do something
}
}
and i have a function: getfile.php
<?php
require_once($GLOBALS['path']."connect.php");
?>
the i have the: connect.php
<?php
function connect( $host, $database )
{
database connection here
}
?>
how can i use this functions inside my class like this:
class Connect
{
require_once("getfile.php");
public function auth()
{
connect( $host, $database )
... do query
}
}
is this possible?
thanks
Functions declared in the global scope is available globally. So you don't have to include it where you need it, just include the file with the function in the beginning of your script.
Secondly,
class Connect
{
require_once("getfile.php");
public function auth()
{
connect( $host, $database )
... do query
}
}
this is just jibberish; you can't execute something inside the class outside of methods. If you really just want something included ONLY when that specific file is needed in that specific method, do something like this:
class Connect
{
public function auth()
{
require_once("getfile.php");
connect( $host, $database )
... do query
}
}