获取数据

有2个方法可以获取数据。 fetchRow() 方法可以返回一条数据, fetchAll() 可以返回多条数据。2个方法都可以使用原生 SQL 语句作为参数。

  1. <?php
  2. use Phinx\Migration\AbstractMigration;
  3. class MyNewMigration extends AbstractMigration
  4. {
  5. /**
  6. * Migrate Up.
  7. */
  8. public function up()
  9. {
  10. // fetch a user
  11. $row = $this->fetchRow('SELECT * FROM users');
  12. // fetch an array of messages
  13. $rows = $this->fetchAll('SELECT * FROM messages');
  14. }
  15. /**
  16. * Migrate Down.
  17. */
  18. public function down()
  19. {
  20. }
  21. }