我目前有一个输出数组的脚本。该数组如下所示:
Array
(
[pattern] => 12369
)
我只想将12369插入到'pattern'列的database.table中。我怎么能用PHP做到这一点?
提前致谢,
答案 0 :(得分:0)
试试这样:
Insert into mytable (pattern) values($arr['pattern');
答案 1 :(得分:0)
假设您知道您的密钥和值是什么并控制它们,这是一个通用的解决方案。
$keys = implode(' ,', array_keys($array));
$values = implode(' ,', $array);
mysqli_query($connection, "INSERT INTO database.table ($keys) VALUES ($values)";
答案 2 :(得分:0)
您可以试试这个,这是一个非常简单的程序,可以在您的数据库中插入任何数据....
<?php
$con=mysqli_connect("localhost","root","password","DBName");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO TableName(pattern)
VALUES ('12369')");
mysqli_close($con);
?>
答案 3 :(得分:0)
$mysqli = new mysqli("localhost", "my_user", "my_password", "database");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query="INSERT INTO table ('pattern') VALUES ('".$array['pattern']."')";
if ($mysqli->query($query) === TRUE) {
printf("value successfully inserted .\n");
}