//连接MySQL数据库 $conn = mysqli_connect("localhost", "root", "password", "database"); //查询数据表 $sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); //输出数据 if(mysqli_num_rows($result) >0){ while($row = mysqli_fetch_assoc($result)){ echo "ID: " . $row["id"] . " - Name: " . $row["name"] . "
"; } } else { echo "0 results"; } //插入数据 $sql = "INSERT INTO users (name, email, password) VALUES ('John Doe', 'john.doe@example.com', '123456')"; if(mysqli_query($conn, $sql)){ echo "New record created successfully"; } else { echo "Error: " . $sql . "
" . mysqli_error($conn); } //关闭MySQL连接 mysqli_close($conn);
MySQL具有高性能、可伸缩性、安全性高等特点,可以应用在各种类型的应用中,包括电子商务、科技企业、政府机构等。