我想知道下面的代码行与密钥有什么区别。
<?php
$subject = $location = $date = $starttime = $endtime = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$subject = $_POST["subject"];
$location = $_POST["location"];
$date = $_POST["date"];
$starttime = $_POST["starttime"];
$endtime = $_POST["endtime"];
$email = $_POST["email"];
$orignal_minutes = $_POST["Oriminutes"];
$edited_minutes = $_POST["Ediminutes"];
}
if($_POST['submit'] != "" )
{
$tablename = "WM_".$subject;
$createTable = "CREATE TABLE `$tablename`(
id INT(6) UNSIGNED AUTO_INCREMENT KEY,
subject VARCHAR(50) NOT NULL, date VARCHAR(20) NOT NULL, location VARCHAR(100) NOT NULL,
starttime VARCHAR(10) NOT NULL, endtime VARCHAR(10) NOT NULL, email VARCHAR(255) NOT NULL,
minutes VARCHAR(MAX) NOT NULL )";
if (mysqli_query($conn, $createTable)){
echo "Table `$tablename` created successfully";}
else{ echo "Error creating table: " . mysqli_error($conn); }
$sql = "INSERT INTO `$tablename` (id, subject, date, location, starttime, endtime, email, minutes )
VALUES (DEFAULT,'$subject','$date','$location', '$starttime' ,'$endtime', '$email','$orignal_minutes')";
mysqli_query($conn,$sql);
}
和
Entity e = new Entity("Employee", 100);
答案 0 :(得分:3)
第一行创建一个标识为Employee
的{{1}}实体,而第二行创建一个100
实体,该实体是在中生成的实体 第一行。
Employee
此行会创建一个种类为Entity e = new Entity("Employee", 100);
且ID为Employee
的新实体。
100
这些行执行以下操作:
Key k = KeyFactory.createKey("Employee", 100);
Entity e = new Entity("Employee", k);
和ID Employee
的实体的密钥。此密钥可用于引用由您共享的第一行代码创建的实体。100
的实体,该实体的祖先是之前创建的密钥所引用的实体。新实体也有一个id,但由于您没有在构造函数中指定它,因此当实体保存到数据存储区时,它将由App Engine生成Employee
。如果您不确定祖先的概念,请查看this documentation page。