PHP Phinx是CakePHP的数据库Seeder /迁移库。
这将创建一个伪造的用户,但是我将如何创建一个具有FOREIGN KEY
(或常规ID引用)到该新用户(即子用户)的id
的行? / p>
<?php
use Phinx\Seed\AbstractSeed;
class UserSeeder extends AbstractSeed
{
public function run()
{
$faker = Faker\Factory::create();
$data = [];
for ($i = 0; $i < 100; $i++) {
$data[] = [
'username' => $faker->userName,
'password' => sha1($faker->password),
'password_salt' => sha1('foo'),
'email' => $faker->email,
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'created' => date('Y-m-d H:i:s'),
];
}
$this->insert('users', $data);
}
}
答案 0 :(得分:1)
这应该返回与SELECT LAST_INSERT_ID()
等效的内容:
$this->getAdapter()->getConnection()->lastInsertId();