SOLVED: Help with classes - generating a database connection
Posted: Mon Jan 12, 2004 2:06 pm
Hi all,
i'm new to PHP, so I might look silly here
Here's the question, I would like to instantiate a Database class, which creates a connection to a MySQL database, and nothing else (just trying things out)
constants.inc contains all the required variables $DB_HOST, $USERNAME etc.
This is database.class.php:
I get a Parse error: parse error, expecting `')'' on the line
I really don't understand why it's not working, it all makes sense to me. Did i miss anything?
Thanks in advance.
i'm new to PHP, so I might look silly here
Here's the question, I would like to instantiate a Database class, which creates a connection to a MySQL database, and nothing else (just trying things out)
Code: Select all
<?php
include("constants.inc");
include("Database.class.php");
$Database = new Database($DB_HOST , $USERNAME , $PW , $DBNAME);
?>This is database.class.php:
Code: Select all
<?php
class Database
{
var $DatabaseHost;
var $DatabaseUser;
var $DatabasePass;
var $DatabaseName;
function Database($1,$2,$3,$4)
{
$this->DatabaseHost = $1;
$this->DatabaseUser = $2;
$this->DatabasePass = $3;
$this->DatabaseName = $4;
$ServerConnection = mysql_pconnect( $this->DatabaseHost , $this->DatabaseUser , $this->DatabasePass
);
if ( !$ServerConnection )
{
echo( "Sorry, but a connection to the server could not be made " . mysql_error() );
}
$DatabaseConnection = mysql_select_db( $this->DatabaseName , $ServerConnection );
if ( !$DatabaseConnection )
{
echo( "Sorry, but a connection to the database could not be made " . mysql_error() );
}
}
}
?>Code: Select all
function Database($1,$2,$3,$4)Thanks in advance.