Ben aşağıdaki kod ile çalışıyorum, ve çalıştırdığınızda ekranda bir şey olsun.
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;
}
}
Ben ModelBase devralan bu sınıf var.
<?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);
}
}
?>
Ve nihayet bir test dosyası var:
include("Lead.php");
echo("Creating new lead");
$L = new Lead;
echo("Inserting info");
$L->firstname = "Dev";
$L->lastname = "Test";
$L->phone = "8885552222";
$L->email = "dev@gmail.com";
$L->notes = "Test this screen.";
echo($L->insert());
echo("Done.");
Ben şu hatayı alıyorum:
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /var/www/html/joshk/test/Lead.php on line 15
Hat 15 public Lead()
fonksiyonu ve ben yanlış bir şey nokta olamaz.