需要 mysqli 准备查询的帮助,然后 php 处理然后更新每一行
Need help for mysqli prepared query then php process then update each row
$query = "SELECT id, noms FROM table ORDER BY id ASC";
$query2 = "UPDATE table SET `noms`=? WHERE `id`=?";
if ($stmt = $link->prepare($query)) {
$stmt2 = $link->prepare($query2);
$stmt2->bind_param('si',$noms,$id);
$stmt->execute();
mysqli_stmt_bind_result($stmt, $id, $noms);
while (mysqli_stmt_fetch($stmt)){
$noms = explode("|", $noms);
for($i=0;$i<count($noms);$i++){
$noms[$i]=$i.':'.$noms[$i];
}
$noms=implode('|',$noms);
$stmt2->execute();
}
}
这就是我想要做的,但是查询之间存在冲突问题。
我怎样才能摆脱这个?
这是简化的。 php 治疗比较复杂。不只是 explode/implode。
在 google.
上找不到解决方案
为什么要使用这个 mysqli_stmt_bind_result($stmt, $id, $noms);
?
你为什么不用这个 $stmt->bind_result($id, $noms);
?
检查此代码:
$query = "SELECT id, noms FROM table ORDER BY id ASC";
$query2 = "UPDATE table SET noms=? WHERE id=?";
if ($stmt = $link->prepare($query)) {
$stmt2 = $link->prepare($query2);
$stmt2->bind_param('si',$noms,$id);
$stmt->execute();
$stmt->bind_result($id, $noms);
while ($stmt->fetch()){
printf ("%s (%i)\n", $noms, $id);
//$stmt2->execute();
}
}
$query = "SELECT id, noms FROM table ORDER BY id ASC";
$query2 = "UPDATE table SET `noms`=? WHERE `id`=?";
if ($stmt = $link->prepare($query)) {
$stmt2 = $link->prepare($query2);
$stmt2->bind_param('si',$noms,$id);
$stmt->execute();
mysqli_stmt_bind_result($stmt, $id, $noms);
while (mysqli_stmt_fetch($stmt)){
$noms = explode("|", $noms);
for($i=0;$i<count($noms);$i++){
$noms[$i]=$i.':'.$noms[$i];
}
$noms=implode('|',$noms);
$stmt2->execute();
}
}
这就是我想要做的,但是查询之间存在冲突问题。 我怎样才能摆脱这个?
这是简化的。 php 治疗比较复杂。不只是 explode/implode。 在 google.
上找不到解决方案为什么要使用这个 mysqli_stmt_bind_result($stmt, $id, $noms);
?
你为什么不用这个 $stmt->bind_result($id, $noms);
?
检查此代码:
$query = "SELECT id, noms FROM table ORDER BY id ASC";
$query2 = "UPDATE table SET noms=? WHERE id=?";
if ($stmt = $link->prepare($query)) {
$stmt2 = $link->prepare($query2);
$stmt2->bind_param('si',$noms,$id);
$stmt->execute();
$stmt->bind_result($id, $noms);
while ($stmt->fetch()){
printf ("%s (%i)\n", $noms, $id);
//$stmt2->execute();
}
}