gpt4 book ai didi

php - 使用 PHP 将数组值插入 MySQL DB

转载 作者:行者123 更新时间:2023-11-29 12:57:45 25 4
gpt4 key购买 nike

我在将数组值插入数据库表时遇到问题...请帮助我解决这个问题...提前致谢...

$array1=([0]=>val1,[1]=>val2,[2]=>val3);
$array2=([0]=>val1,[1]=>val2,[2]=>val3);
$array3=([0]=>val1,[1]=>val2,[2]=>val3);

INSERT INTO table1 (id,date,col1,col2,col3,col4) VALUES (1,now(),'$array1','$array2','$array3',50);

最佳答案

你可以这样尝试,(这只是一个例子)

foreach($array as $row){
$query="INSERT INTO
table1 (id,date,col1,col2,col3,col4)
VALUE
(1,now(),".$row['yourfieldname'].",".$row['yourfieldname'].",".$row['yourfieldname'].",50)";
}

关于php - 使用 PHP 将数组值插入 MySQL DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23780444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com