【发布时间】:2018-01-19 01:36:57
【问题描述】:
我有一个字符串数组,它们是 sql“输入到...”查询。我遍历这个数组,将它们中的每 50 个组合成一个新字符串,然后发送到 mysql 数据库。之后,我重置了我的临时字符串并为新查询做准备。
但我的数组在第一次查询后停止并且不想在数据库服务器上发送所有内容,所以我总是只有 50 条记录。如何修复我的代码并发送所有内容?
代码:
$data // array with sql queries
$queryPartial = ''; // additional string for 50 queries to send
foreach ($data as $index => $queryToSend) {
$queryPartial .= $queryToSend;
// send partials query
if($index % 50 == 0)
{
if($connection->multi_query($queryPartial))
{
$this->output->writeln('succesfull query number: '.$index);
}
$queryPartial = ''; // clean string for next queries
}
}
//send the rest of the remaining queries
if($queryPartial !== ''){
if($connection->multi_query($queryPartial))
{
$this->output->writeln('rest of the queries sended');
}
}
$connection->close();
【问题讨论】: