Support
Quality
Security
License
Reuse
kandi has reviewed phinx and discovered the below as its top functions. This is intended to give you an instant insight into phinx implemented functionality, and help decide if they suit your requirements.
Write database migrations using database agnostic PHP code.
Migrate up and down.
Migrate on deployment.
Seed data after database creation.
Get going in less than 5 minutes.
Stop worrying about the state of your database.
Take advantage of SCM features such as branching.
Integrate with any app.
Composer
curl -sS https://getcomposer.org/installer | php
QUESTION
Fetch data for a select query in yii migrations
Asked 2021-May-12 at 14:01I am creating a parent child table using yii migration where there is a foreign key on the child table. I tried using execute but that did not help me fetching the data needed. Is there a way I can query the parent table and insert the parent id on the child table as a foreign key? Something like fetch()/fetchAll() that is used inside phinx migrations.
$this->batchInsert('{{%parent_table}}',
['name'],
[
['P1'],
['P2'],
['P3'],
['P4']
]
);
$a = $this->execute("select * from parent_table where name = 'P1'");
// get the data from the table that will get me the id from the above query.
$this->batchInsert('{{%child_table}}',
[['name'],['parent_id']],
[
['C1','<parent id>'],
['C2','<parent id>'],
.
.
.
]
);
ANSWER
Answered 2021-May-11 at 22:38You need to use
$res = Yii::$app->db->createCommand("select * from parent_table where name = 'P1'")->queryAll();
The $this->execute()
is used to execute sql statements like update or delete instead
Edit
Better use $this->db
instead of Yii::$app->db
to make sure you are running on the same db, as mentioned in the comments
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Explore Related Topics