数据库:插入行多查询


Database: inserting rows multi-query

当我点击提交按钮时,除了没有将字符串的名称放入数组之外,一切都工作了,我在每行的列名下获得了行中的名称"array"。我一整天都在修改代码,但还是没弄明白。注意,我的数组里面有超过130个字符串。

你可以在一个表中放入无限数量的行,对吗?关于如何解决名称问题和增加我的"限制0,30"有什么建议吗?

下面是我的代码:

:

$array = ("","","");
$random = $array;
shuffle($random);

:

$array = ("","","");

仍然不工作。我也试过mysqli_stmt_send_long_data也不能让它工作。

<?php
include ('login-home.php');
$mysqli = new mysqli("", "", "", "");
if ($mysqli->connect_error) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_error . ") " . $mysqli->connect_error;
}
if (!$mysqli->query("INSERT INTO table(id, name) VALUES (id, '".$array."')")) {
    echo "Multi-INSERT failed: (" . $mysqli->error . ") " . $mysqli->error;
}
/* Prepared statement, stage 2: bind and execute */
$id = 1;
if (!$stmt->bind_param("s", $id)) {
    echo "Binding parameters failed: (" . $stmt->error . ") " . $stmt->error;
}
if (!$stmt->execute()) {
    echo "Execute failed: (" . $stmt->error . ") " . $stmt->error;
}
for ($id; $id = $id+1; $id++) {
    if (!$stmt->execute()) {
        echo "Execute failed: (" . $stmt->error . ") " . $stmt->error;
    }
}
$stmt->close();
?>

你可能得到数组插入,因为变量是一个数组。

try to

echo $array; /// the output will be array

所以如果你想获得数组的值插入到db您必须首先使用连接和foreach循环或任何PHP函数将它们转换为字符串这样就行了。比如爆炸,内爆等等。

将转换为

$array = ("ar1","ar2","ar3"); 

$array = "ar1,ar2,ar3";