Jump to content

[SOLVED] OOP basic Syntax help


HoTDaWg

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.