I'm working with the following code, and when run I get nothing displayed on the screen.
class ModelBase
{
public $db_server;
public $db_user;
public $db_password;
static $db_conn;
public static $DBSERVER="localhost";
public static $DBUSER="user";
public static $DBPASSWORD="password";
public static $DBNAME="test";
function ModelBase()
{
if(!isset(self::$db_conn))
{
$this->db_server = ModelBase::$DBSERVER;
$this->db_user = ModelBase::$DBUSER;
$this->db_password = ModelBase::$DBPASSWORD;
self::$db_conn = mysql_connect($this->db_server, $this->db_user, $this->db_password) or die(mysql_error(0)." Error handling database connection. ");
mysql_select_db(ModelBase::$DBNAME) or die("Couldn't select database.");
return self::$db_conn;
}
}
static function getConnection()
{
if (!isset(self::$db_conn))
{
self::$db_conn = mysql_connect($this->db_server, $this->db_user, $this->db_password) or die(mysql_error(0)." Error handling database connection. ");
mysql_select_db(ModelBase::$DBNAME) or die("Couldn't select database.");
}
return self::$db_conn;
}
}
I have this class that inherits ModelBase.
<?php
include("ModelBase.php");
?>
<?php
class Lead extends ModelBase
{
public $id;
public $firstname;
public $lastname;
public $phone;
public $email;
public $notes;
public Lead()
{
}
public insert()
{
$con = ModelBase::getConnection();
$query = "insert into test (id, firstname, lastname, phone, email, notes) values('','".$this->firstname."','".$this->lastname."','".$this->phone."','".$this->email."','".$this->notes."')";
$res = mysql_query($query, $con) or die(mysql_error(0)." Error inserting ".$query);
return($res);
}
}
?>
And finally I have a test file:
include("Lead.php");
echo("Creating new lead");
$L = new Lead;
echo("Inserting info");
$L->firstname = "Dev";
$L->lastname = "Test";
$L->phone = "8885552222";
$L->email = "[email protected]";
$L->notes = "Test this screen.";
echo($L->insert());
echo("Done.");
I'm getting the following error:
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /var/www/html/joshk/test/Lead.php on line 15
Line 15 is the public Lead()
function and I can't spot anything wrong with that.