HoTDaWg Posted May 17, 2009 Share Posted May 17, 2009 hi there, im having difficulty passing simple text in quotes to a method. here is the class: <?php error_reporting(E_ALL); class DbActions { protected $dausername = "******"; protected $dapassword = "********"; public $datarbase; protected $hostess = "localhost"; var $result; var $result_message; var $dalink; function DbConnect () { $this->dalink = mysql_connect($this->hostess,$this->dausername,$this->dapassword); if (!$this->dalink) { mysql_error(); echo "Failed to connect to database. <br>"; exit(); } } public function DbReach($databarbase) { echo $this->datarbase; $this->result = mysql_select_db($this->datarbase,$this->dalink) or die (mysql_error()); if ($this->result) { $this->result_message = " successfully established connection with database <br>"; } else { $this->result_message = " failed to connect to database <br>"; } } } ?> i call upon the class and function with: <?php require ("connect.php"); $connection = new DbActions(); $connection -> DbConnect(); $connection -> DbReach("main"); echo $connection->result_message; ?> however, the mysql error message it gives me is No database selected to reiterate, I am trying to pass the word "main" to the function DbReach but i dont think im doing it right? any idea how to do this properly? thanks HoTDaWg Link to comment https://forums.phpfreaks.com/topic/158449-solved-oop-basic-syntax-help/ Share on other sites More sharing options...
HoTDaWg Posted May 17, 2009 Author Share Posted May 17, 2009 hahahaha never mind simple typo take a look at the brackets for DbReach:P heres how the function should have looked: <?php //...previous code here... public function DbReach($datarbase) { $this->datarbase = $datarbase; $this->result = mysql_select_db($this->datarbase,$this->dalink) or die (mysql_error()); if ($this->result) { $this->result_message = " successfully established connection with database <br>"; } else { $this->result_message = " failed to connect to database <br>"; } } thanks for the help guys! sorry i didnt mean to waste time like this... Link to comment https://forums.phpfreaks.com/topic/158449-solved-oop-basic-syntax-help/#findComment-835625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.