execute(); $result = $stm-6ren">
gpt4 book ai didi

php - 插入 mysqli_result 对象

转载 作者:行者123 更新时间:2023-11-29 06:27:51 25 4
gpt4 key购买 nike

我有一个 mysqli_result:

$stmt = $db->prepare("SELECT * FROM customer");
$stmt->execute();
$result = $stmt->get_result();

是否可以直接使用此结果执行 INSERT? (数据需要转移到另一个数据库中)例如$another_db->insert($result)或者至少将整个结果对象转换为简单的Mysql插入字符串而不迭代结果。

最佳答案

我做了这样的解决方法:

$stmt = $db->prepare("SELECT * FROM customer");
$stmt->execute();
$result = $stmt->get_result();
$newsql="";
while($row = $result->fetch_object())
{
$newsql = "INSERT INTO customer VALUES (";
foreach($row as $key => $value)
{
$newsql .= "'".mysqli_real_escape_string($db,$value)."',";
}
$newsql = substr($newsql,0,-1);
$newsql .="); ";
}
// $newsql can be inserted.

关于php - 插入 mysqli_result 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58461825/

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