PHPでCRUDクラスを作ろうとしています。私は基本的に、自分がすることすべてを OO にすることに固執しようとしています。私の質問は、フォームの値をクラス自体に送信する方法です。このファイル名に出力する標準フォームがあります。
ただし、適切なクラスを参照するにはそれが必要です... 事前に助けを求めて乾杯!
<?php
require('connection/connection.php');
class Crud{
public function __construct(){
$v_title = $_POST['v_id'];
$v_title = $_POST['v_title'];
$v_features = $_POST['v_features'];
$yt_id = $_POST['yt_id'];
$v_subject = $_POST['v_subject'];
$taname = "videohubapp";
echo $v_title;
}
protected static function Create($v_id, $v_title, $v_features, $yt_id, $v_subject){
#Creates entries
$query = $conn->prepare("INSERT INTO $taname (v_title, v_features, yt_id, v_subject) VALUES (:v_title, :v_features, yt_id, v_subject)");
$query->bindParam(":v_title", $v_title);
$query->bindParam(":v_features", $v_features);
$query->bindParam(":yt_id", $yt_id);
$query->bindParam(":v_subject", $v_subject);
$query->execute();
}
public static function Read($v_id, $v_title, $v_features, $yt_id, $v_subject){
#Reads database entries
$query = $conn->prepare("SELECT * FROM $taname ORDER BY v_id");
$query->setFetchMode(PDO::FETCH_ASSOC);
while($row = $conn->fetch())
{
echo $row['v_id'] . "\n";
echo $row['v_title'] . "\n";
echo $row['v_features'] . "\n";
echo $row['yt_id'] . "\n";
echo $row['v_subject'] . "\n";
}
}
protected static function Update($v_id, $v_title, $v_features, $yt_id, $v_subject){
#Updates database entries
$query = $conn->prepare("UPDATE $taname SET (v_title = :v_title, v_features = :v_features, yt_id = :yt_id, v_subject = :v_subject) WHERE v_id = :v_id");
$query->bindParam(":v_id", $v_id);
$query->bindParam(":v_title", $v_title);
$query->bindParam(":v_features", $v_features);
$query->bindParam(":yt_id", $yt_id);
$query->bindParam(":v_subject", $v_subject);
$query->execute();
}
protected static function Delete($v_id, $v_title, $v_features, $yt_id, $v_subject){
#Delete entries from the database
$query = $conn->prepare("DELETE FROM $taname WHERE v_id = :v_id");
$query->bindParam(":v_id", $v_id);
$query->execute();
}
public static function XMLWebService(){
#XMLParse
$query = $conn->prepare("SELECT * FROM $taname");
$query->execute();
}
}
?>