jonsamwell Posted January 12, 2009 Share Posted January 12, 2009 Hi, I am having problems getting this method to see the variables! I keep getting the error. 'Fatal error: Cannot access empty property in C:\wamp\www\parser\Parser\Database\Database_Connection.php on line (db_connect() method)' I don't understand why the variables are seen as empty as they are intitalised???? class Database_Connection { var $username = 'User_main'; var $password = 'password'; var $server = 'localhost'; var $database_name = 'pricing'; var $link_identifier = null; function _constructor() {//Default Constructor } function db_connect() { $this->$link_identifier = mysql_connect($this->$server, $this->$username, $this->$password); } } If i hard code the values everything works fine. Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 All of your $this -> $varName should be $this -> varName Without the $ sign Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735637 Share on other sites More sharing options...
Mchl Posted January 12, 2009 Share Posted January 12, 2009 'var' is a thing of PHP4, and constructor method is called __construct() in PHP5. Oh... and perhaps you should try mysqli if you're going into OOP. Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735641 Share on other sites More sharing options...
jonsamwell Posted January 12, 2009 Author Share Posted January 12, 2009 cool thanks work, just trying to go from 'normal' php to OO What is mysqli? has it got foriegn key abilities?? regards, Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735644 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Change var to public (the equivalent), read up on some php 5 OOP tutorials Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735647 Share on other sites More sharing options...
dennismonsewicz Posted January 12, 2009 Share Posted January 12, 2009 whats the big difference between mysql and mysqli? Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735651 Share on other sites More sharing options...
Mchl Posted January 12, 2009 Share Posted January 12, 2009 mysqli stands for "mysql Improved". It's recommended extension to use, when connecting to MySQL server version 4.1 or later. Foreign key capability is a thing of storage engine itself. MyISAM doesn't have it, InnoDB does. whats the big difference between mysql and mysqli? It's object oriented, enables use of prepared statements (and some other features, that mysql lacks), it is said to be faster. Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735654 Share on other sites More sharing options...
dennismonsewicz Posted January 12, 2009 Share Posted January 12, 2009 ah gotcha... i am slowly filtering in PHP5 (OOP) into my every day programming... very new to it.. kinda confusing lol Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735662 Share on other sites More sharing options...
DarkSuperHero Posted January 12, 2009 Share Posted January 12, 2009 Doing the same here....i find it dificult to not make things over complicated sometimes...i end up getting rid of something i dont need in my OO code all the time... i star out thinking i think i need it when in fact i dont/wont.. :-) cheers! Quote Link to comment https://forums.phpfreaks.com/topic/140573-silly-oo-problem/#findComment-735713 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.