Jump to content

Can i use Define function like this.........


jeeva

Recommended Posts

hi frnds,

 

can i declare the php function as a constant like

define("CONNECT","odbc_connect");.

 

if i used like that than it will gives the error message.i don't know we can use or should not use

 

here my code

define("CONNECT","odbc_connect");
class db
{

var $dsn="dbconnect"; //dsn
var $uname="";
var $password="";
var $con=NULL;


//db connect
function DbConnect()
{
	$this->con=CONNECT($this->dsn,$this->uname,$this->password) or die(odbc_errormsg());
	return $this->con;
}
}

 

it's gives the following error

Fatal error: Call to undefined function: connect() in c:\inetpub\wwwroot\access\class.php on line 22

 

wts up?

 

Link to comment
https://forums.phpfreaks.com/topic/39124-can-i-use-define-function-like-this/
Share on other sites

PHP is a scripting language and does not go through and replace constants first like pre-processor directives. To do such a thing, you would have to do it this way:

 

$CONNECT="odbc_connect";
...
$this->con=$CONNECT($this->dsn,$this->uname,$this->password) or die(odbc_errormsg());

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.