试图在 PHP 中创建一个 CRUD 类。我基本上是在努力坚持让我做的一切都是面向对象的。我的问题是,如何将表单值提交给类本身,我有一个标准表单,它只是输出到这个文件名。
但是,我需要它来引用正确的类......提前为帮助干杯!
<?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();
}
}
?>