LoginSignup
0
0

More than 5 years have passed since last update.

PHPでSQLiteのID欠番を寄せて連番に直す方法。

Last updated at Posted at 2015-12-01
<?php
  $db = new SQLite3("[データベースファイル名]");
  $table = "[テーブル名]";
  $query = "SELECT * FROM $table";
  $result = $db->query($query);
  $new_id = 1;
  while ($row = $result->fetchArray()) {
    $id = $row["id"];
    if ($new_id !== $id){
      echo "$new_id : $id \n";
      $query= "UPDATE $table SET id = $new_id WHERE id = $id";
      $result1 = $db->query($query);
    }
    $new_id += 1;
  }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0