Jump to content

error w/ mysql connection class.


cypher_block

Recommended Posts

What am I doing wrong here?

 

$config = array('db'=>'ir_db', 'host'=>'localhost', 'username'=>'root','password'=>'root');

class connect
{
private $host = $config['host'];
private $db =$config['db'];
private $username = $config['username'];
private $password = $config['password'];

public function connect()
{
$connection = mysql_connect($this->host,$this->username,$this->password)
or die('Could not connect:'.mysql_error());

$db = mysql_select_db($this->db) or die ('Could not select db:'.mysql_error());
}

}   

 

I get a "Parse error: syntax error, unexpected T_VARIABLE" on line 9, which is the first private var i declare.

 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/98713-error-w-mysql-connection-class/
Share on other sites

Ok, I know part of the problem is scope, but can i not do this?  apparently not because i still get an error, but dont understand why?


class connect
{
global $config;
private $host = $config['host'];
private $db =$config['db'];
private $username = $config['username'];
private $password = $config['password'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.