phinx: Can't update database in migration
I’m trying to run a loop over a particular large database table which can’t be loaded into memory at the same time. I can’t really see much wrong with what I wrote. But perhaps there is something I’m missing.
The up() method looks like this
$processed = 0;
$tables = "countries"
while(true){
/** @var PDOStatement $stmt */
$stmt = $this->query("select id,name from $table order by id limit 100 offset $processed");
if($stmt->rowCount() === 0){
print("No more data in table '$table'\n");
break;
}
while($row = $stmt->fetch()){
$id = $row["id"];
$this->execute("update $table set slug='hello' where id='$id'");
$processed++;
}
}
At the end, I expected that the table would hold slugs with hello in them. But to my surprise, it’s a completely empty column.
What am I doing wrong here? I must be blind to something.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (6 by maintainers)
up()is executed herehttps://github.com/cakephp/phinx/blob/c34ace8a284953043f36386c92fa9326483e00ac/src/Phinx/Migration/Manager/Environment.php#L128
So yes, call commit/begin transaction on adapter.