I am pretty new to PHP. My background is C / C ++ and C #. I am trying to create an object orientational PHP code, but I am doing something wrong.
Class Code:
class ConnectionString { public $String = ""; public $HostName = ""; public $UserName = ""; public $Password = ""; public $Database = ""; function LoadFromFile($FileName) { $this->String = file_get_contents($Filename); $Values = explode("|", $this->String); $this->HostName = $Values[0]; $this->UserName = $Values[1]; $this->Password = $Values[2]; $this->Database = $Values[3]; } }
Call Code:
$ConnectionString = new ConnectionString(); $FileName = "db.conf"; $ConnectionString->LoadFromFile($FileName); print('<p>Connection Info: ' . $Connection->String . '</p>');
I get an ann error in the line file_get_contents($Filename) stating: the file name cannot be empty. If I hardcode the file name instead of $ Filename, then I just get all the empty lines for the fields.
What simple concept am I missing?
php
John craft
source share