PHP数组爆炸两次
我有一个数组,需要插入到数据库的多行中。数组的结构如下所示:PHP数组爆炸两次,php,arrays,oracle,Php,Arrays,Oracle,我有一个数组,需要插入到数据库的多行中。数组的结构如下所示: $var = "Name1,Age1,DOB1,Relation1.Name2,Age2,Dob2,Relation2.";//And so on, depending on users input (点表示新行,逗号表示新列) 我需要像这样将其插入数据库: 我首先将所有行存储在如下数组中: $rowsToInsert = explode (".",$var); $rowsToInsert[0] = Name1,Age1,DOB1
$var = "Name1,Age1,DOB1,Relation1.Name2,Age2,Dob2,Relation2.";//And so on, depending on users input
(点表示新行,逗号表示新列)
我需要像这样将其插入数据库:
我首先将所有行存储在如下数组中:
$rowsToInsert = explode (".",$var);
$rowsToInsert[0] = Name1,Age1,DOB1,Relation1;
$rowsToInsert[1] = Name2,Age2,DOB2,Relation2;
...And So on...
我现在有:
$rowsToInsert = explode (".",$var);
$rowsToInsert[0] = Name1,Age1,DOB1,Relation1;
$rowsToInsert[1] = Name2,Age2,DOB2,Relation2;
...And So on...
问题:
$rowsToInsert = explode (".",$var);
$rowsToInsert[0] = Name1,Age1,DOB1,Relation1;
$rowsToInsert[1] = Name2,Age2,DOB2,Relation2;
...And So on...
将这些数组元素存储到包含名称、年龄、DOB、关系列的数据库中的最快方法是什么?可能是这样的吗
$rows = explode (".",$var);
$addslash = addslashes($rows);
foreach($addslash as $val) {
$val_str = str_replace("," ,"','", $val);
$sql = "INSERT INTO tablename (Name, Age, DOB, Relation) VALUES ('" .$val_str. "')";
}