<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "INSERT INTO mytable (name, phone, email) VALUES ('Charles', '04-12345678', 'charles@com88.tw')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $sql = "SELECT name, phone, email FROM mytable"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "name: " . $row["name"]. " - phone: " . $row["phone"]. " - email: " . $row["email"]. "<br>"; } } else { echo "0 results"; } $sql = "UPDATE mytable SET phone='04-23456789' WHERE name='Charles'"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } $sql = "DELETE FROM mytable WHERE name='Charles'"; if ($conn->query($sql) === TRUE) { echo "Record deleted successfully"; } else { echo "Error deleting record: " . $conn->error; } $conn->close(); ?>
文章標籤
全站熱搜
留言列表