HexCoder Posted July 7, 2012 Share Posted July 7, 2012 hello every one... when in want to run my php code i get somthings like this error : Fatal error: Cannot access empty property in C:\xampp\htdocs\cms-project\include\DBconnector.php on line 14 and my DBconnector.php file code is this : <?php //dbconnector class require_once 'systemcomponents.php'; class DBconnector extends systemcomponents{ var $link; var $thisquery; function DBconnector(){ $settings= systemcomponents::getsettings(); $dbname=$settings['dbname']; $hostname=$settings['dbhost']; $dbusername=$settings['dbusername']; $dbpass=$settings['dbpassword']; //connect to data base $this->$link=mysql_connect($hostname,$dbusername,$dbpass); mysql_select_db($dbname); register_shutdown_function(array(&$this,'close')); function query($query){ $this->$thisquery=$query; return mysql_query($query,$this->$link); } function fetchquery($queryresult){ return mysql_fetch_array($queryresult); } function close(){ mysql_close($this->$link); } } } ?> please help me to resolve problem.. TanQ Quote Link to comment https://forums.phpfreaks.com/topic/265348-cannot-access-empty-property-error/ Share on other sites More sharing options...
requinix Posted July 7, 2012 Share Posted July 7, 2012 When accessing member variables and methods you do not include a $ with the variable name. $this->link=mysql_connect($hostname,$dbusername,$dbpass); $this->thisquery=$query; Quote Link to comment https://forums.phpfreaks.com/topic/265348-cannot-access-empty-property-error/#findComment-1359859 Share on other sites More sharing options...
HexCoder Posted July 7, 2012 Author Share Posted July 7, 2012 i remove $ and get new error : Fatal error: Call to undefined method DBconnector::query() in C:\xampp\htdocs\cms-project\index.php on line 5 and this is my index.php code : <?php require_once('include/DBconnector.php'); $connectdb=new DBconnector(); $result=$connectdb->query("SELECT username FROM userinfo"); $row=$connectdb->fetchquery($result); echo $row['username']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/265348-cannot-access-empty-property-error/#findComment-1359911 Share on other sites More sharing options...
xyph Posted July 7, 2012 Share Posted July 7, 2012 >_< Download a text editor that supports syntax highlighting. You never close your constructor function, until the end of the class. Quote Link to comment https://forums.phpfreaks.com/topic/265348-cannot-access-empty-property-error/#findComment-1359917 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.