将类定义添加到StoreUser.php文件并从store.php文件中调用它后,我做错了什么,因为它不起作用?它在文件StoreUser.php中运行良好,没有类定义和函数,见下文。
$dbhost = "localhost";
$dbname = "riskinarviointilomake";
$dbuser = "root";
$dbpass = "";
//private $email;
if(isset($_GET["email"])){
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (!( $stmt = $conn->prepare("INSERT INTO users(unique_id,email,
encrypted_password) VALUES(?,?,?)"))){
echo "Table creation failed: (" . $conn->errno . ") " . $conn->error;
}
$stmt->bind_param('sss', $unique_id,$email,$password);
$unique_id=123457764;
$password="df12467hh";
$result = $stmt->execute();
$stmt->close();
$conn->close();
}
?>
这不起作用
class StoreUser{
$dbhost = "localhost";
$dbname = "riskinarviointilomake";
$dbuser = "root";
$dbpass = "";
//private $email;
public function store($email){
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (!( $stmt = $conn->prepare("INSERT INTO users(unique_id,email, encrypted_password) VALUES(?,?,?)"))){
echo "Table creation failed: (" . $conn->errno . ") " . $conn->error;
}
$stmt->bind_param('sss', $unique_id,$email,$password);
$unique_id=123457764;
$password="df12467hh";
$result = $stmt->execute();
$stmt->close();
$conn->close();
}
}
<?php
include 'StoreTest.php';
if(isset($_GET['email'])){
$email = $_GET['email'];
$store = new StoreTest();
$store->store($email);
}
?>