View Single Post
Old 02-12-2009, 04:09 PM   #1 (permalink)
9three
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default Adding database name within the initial parameters

Hey,

What I'm trying to accomplish is add the database name within the first line to avoid having two lines. This is what I mean:

PHP Code:
$connection = new mysql('localhost''root''''cms');
$query "SELECT ID, Username, Password, Email FROM admins";
$connection->query($query); 
It's throwing me an exception saying that I did not select a database.

I'm trying to avoid this:

PHP Code:
$connection = new mysql('localhost''root''');
$connection->select(cms);
$query "SELECT ID, Username, Password, Email FROM admins";
$connection->query($query); 
Here is my class file:

PHP Code:
  public function __construct($host ''$username ''$password ''$dbname '')
  {
    
$this->host $host;
    
$this->username $username;
    
$this->password $password;
    
$this->dbname $dbname;
    
$this->connect();
  }
  
  public function 
connect()
  {
    
$this->link mysql_connect($this->host$this->username$this->password);
    if (!
is_resource($this->link))
      Throw New 
Exception(mysql_error());
    else
      return 
$this->link;
  }
  
  public function 
select()
  {
    
$this->select mysql_select_db($this->dbname$this->link);
    if (!
is_resource($this->select))
      Throw New 
Exception(mysql_error());
    else
      return 
$this->select;
  } 
I thought this was the way to do it but I guess I was wrong. Anyone know how to fix the parameters?
9three is offline  
Reply With Quote