私は自分が開発しているクラスのフレームワークを使用していて、それを終了する前にテストを投げています。
ただし、実行を妨害しているように見えるいくつかのエラーが発生します。
これがphpの警告/エラーです:
Notice: A session had already been started - ignoring session_start() in
/var/www/VRC_Header2.php on line 2
Strict Standards: Redefining already defined constructor for class CheckOut in
/var/www/CheckOut_old.php on line 18
そして、ここに関係する2つのクラスがあります:
<?php //Checkout class - NOTE: Add exception handler later
class CheckOut extends DB_MySQL{
public $fName;
public $lName;
public $numberOut;
public $p_id;
public function __construct($dbuser, $dbpass, $dbhost, $dbname)
{
parent::__construct($dbuser, $dbpass, $dbhost, $dbname);
$this->connect();
}
//Grab the values of the territory being checked out
public function checkOut($numberOut)
{
$this->numberOut=$numberOut;
/*
*Begin checkout function that inserts into database.
*Make sure all tests are run BEFORE calling this method.
*Begin checkout function:
*/
//Check Connection
$this->checkConnect();
//Start Checkout
$stmt = $this->dbh->prepare("INSERT INTO checkOut(t_id, p_id, checkTime, due) VALUES(:param1, :param2, curdate(), date_add(curdate(), interval 3 month))");
$stmt->bindParam(':param1', $this->numberOut);
$stmt->bindParam(':param2', $this->p_id);
$stmt->execute();
if($stmt == FALSE)
return false;
else
return true;
}
private function checkConnect()
{
if(!isset($this->dbh))
$this->connect();
}
public function territoryCheck($numberOut)
{
$this->numberOut = $numberOut;
//Execute test
$this->checkConnect();
$stmt = $this->dbh->prepare("SELECT t_id FROM Territory WHERE t_id = :param1");
$stmt->bindParam(':param1', $this->numberOut);
$stmt->execute();
$stmt->fetch();
//Determine value of test
if($stmt == FALSE)
{
return FALSE;
}
}
public function publisherCheck($lName, $fName)
{
$this->lName = $lName;
$this->fName = $fName;
//Execute test
$this->checkConnect();
$stmt = $this->dbh->prepare("SELECT p_id FROM People WHERE lastName = :param1 AND firstName = :param2");
$stmt->bindParam(':param1', $this->lName);
$stmt->bindParam(':param2', $this->fName);
$stmt->execute();
//Determine value of test
if($stmt == FALSE)
{
return FALSE;
}
else
{
$dummyvar = $stmt->fetch();
$this->p_id = implode($dummyvar);
}
}
public function isTerritoryOut($numberOut)
{
//Execute test
$this->checkConnect();
$this->numberOut = $numberOut;
$stmt = $this->dbh->prepare("SELECT t_id FROM checkIn WHERE t_id = :param1");
$stmt->bindParam(':param1', $this->numberOut);
$stmt->execute();
$stmt->fetch();
//Determine value of test
if($stmt == FALSE)
{
return FALSE;
}
}
}
?>
そして他:
include 'VRC_Header2.php';
class DB_MySQL {
protected $dbuser;
protected $dbpass;
protected $dbhost;
protected $dbname;
protected $dbh; // Database connection handle
public function __construct($dbuser, $dbpass, $dbhost, $dbname)
{
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->dbhost = $dbhost;
$this->dbname = $dbname;
}
//Used to create connections - almost always called by execute()
protected function connect()
{
try
{
$this->dbh = new PDO("mysql:host=$this->dbhost;dbname=$this->dbname",$this->dbuser,$this->dbpass);
}
catch(PDOException $e)
{
print "Error!: ".$e->getMessage()."<br/>";
die();
}
}
}
?>
クラスは完全ではありませんが、機能しています。さて、本当の問題はコンストラクターに関係していると感じています(もちろんエラーです)。しかし、その問題と私が受け取った答えに関して以前に投稿した質問があります:子クラスのコンストラクターはphpの親クラスのコンストラクターとどのように相互作用しますか?。
ここで何が問題になっていますか?
どんな助けでも大歓迎です。
編集:クラスに渡した値もデータベースに挿入されないように追加する必要があります。エラーの結果だと思います/