3. Insert Into增加语句
INSERT INTO 语句用于向数据库表添加新记录。
INSERT INTO table_name
VALUES (value1, value2,....)
您还可以规定希望在其中插入数据的列:
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)
注释:SQL 语句对大小写不敏感。INSERT INTO 与 insert into 相同。
示例:
<?php
$servername ="localhost";
$username ="username";
$password ="password";
$dbname ="myDB";
// 创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
// 检测连接
if(!$conn){
die("Connection failed: ". mysqli_connect_error());
}
//一条一条写入数据
$sql ="INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if(mysqli_query($conn, $sql)){
echo "新记录插入成功";
}else{
echo "Error: ". $sql ."<br>". mysqli_error($conn);
}
/* 多条写入数据
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com');";
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('Mary', 'Moe', 'mary@example.com');";
$sql .= "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('Julie', 'Dooley', 'julie@example.com')";
if (mysqli_multi_query($conn, $sql)) {
echo "新记录插入成功";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
*/
mysqli_close($conn);
?>
--------------------------------------------------------------------
承接网站开发、小程序开发、app开发、商城开发、公众号开发。
百度SEO排名、百度搜索霸屏、软文代写等业务。
联系QQ:2779459018 联系微信:qianxia39