在PHP中,可以使用SQL語(yǔ)句將報(bào)表數(shù)據(jù)寫(xiě)入數(shù)據(jù)庫(kù)。首先,需要連接到數(shù)據(jù)庫(kù)并構(gòu)建一個(gè)SQL語(yǔ)句來(lái)插入數(shù)據(jù)。
以下是一個(gè)示例代碼:
//連接到數(shù)據(jù)庫(kù)
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//構(gòu)建SQL語(yǔ)句
$sql = "INSERT INTO reports (report_name, report_date, report_data) VALUES ('Report1', '2021-01-01', 'Some data for report 1')";
//執(zhí)行SQL語(yǔ)句
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
//關(guān)閉數(shù)據(jù)庫(kù)連接
$conn->close();
在上面的示例中,連接到數(shù)據(jù)庫(kù)后,構(gòu)建了一個(gè)插入報(bào)表數(shù)據(jù)的SQL語(yǔ)句,然后執(zhí)行該SQL語(yǔ)句。如果插入成功,將輸出"New record created successfully",否則將輸出錯(cuò)誤信息。
需要根據(jù)實(shí)際情況修改數(shù)據(jù)庫(kù)連接信息、SQL語(yǔ)句和報(bào)表數(shù)據(jù)。