Notice: Undefined variable: serverName in C:\inetpub\wwwroot\portal2\inc\dbIntranet.php on line 13
What's up?
PHP
Last Comment
Robert Francis
8/22/2022 - Mon
gr8gonzo
header.php is defining $serverName in the global scope. Code inside of a function or a class method can't see the global scope automatically - they only see the variables that are passed in or otherwise made explicitly available to them.
So you -could- do this to your class definition:
class dbIntranet {
private $connIntranet; private $serverName; // New class property called serverName
function __construct($serverName){ // Change the constructor to accept a new parameter $this->serverName = $serverName; // Copy the value of the parameter to the class property
$this->open_connection();
}
public function open_connection() {
$this->connIntranet = sqlsrv_connect($this->serverName, $connectionInfoIntranet); <-----LINE 13
}
...and then when you created a new instance of dbIntranet, you pass in your global variable:
So you -could- do this to your class definition:
class dbIntranet {
private $connIntranet;
private $serverName; // New class property called serverName
function __construct($serverName){ // Change the constructor to accept a new parameter
$this->serverName = $serverName; // Copy the value of the parameter to the class property
$this->open_connection();
}
public function open_connection() {
$this->connIntranet = sqlsrv_connect($this->serverName, $connectionInfoIntranet); <-----LINE 13
}
...and then when you created a new instance of dbIntranet, you pass in your global variable:
$x = new dbIntranet($serverName);