PHP:PHP插入多条数据

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43731793/article/details/91044655

1、插入多条数据

<?php
$servername = "localhost";
$username = "root";
$password = "123456";
 $dbname = "mysql2";
 
// 创建链接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检查链接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
 
$sql = "INSERT INTO mysql3 (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com');";
$sql = "INSERT INTO mysql3 (firstname, lastname, email)
VALUES ('Mary', 'Moe', 'mary@example.com');";
$sql = "INSERT INTO mysql3 (firstname, lastname, email)
VALUES ('Julie', 'Dooley', 'julie@example.com')";
 
if ($conn->multi_query($sql) === TRUE) {
    echo "新记录插入成功";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
 
$conn->close();
?>
展开阅读全文

没有更多推荐了,返回首页