Skip to content

Latest commit

 

History

History
95 lines (57 loc) · 2.29 KB

db_commands.rst

File metadata and controls

95 lines (57 loc) · 2.29 KB

Database Commands

CodeIgniter provides some simple commands for database management.

db:table --show

To list all the tables in your database straight from your favorite terminal, you can use the db:table --show command:

php spark db:table --show

When using this command it is assumed that a table exists. Otherwise, CodeIgniter will complain that the database has no tables.

db:table --dbgroup

.. versionadded:: 4.5.0

You can specify the database group to use with the --dbgroup option:

php spark db:table --show --dbgroup tests

db:table

When you have a table named my_table, you can see the field names and the records of a table:

php spark db:table my_table

If the table my_table is not in the database, CodeIgniter displays a list of available tables to select.

You can also use the following command without the table name:

php spark db:table

In this case, the table name will be asked.

You can also pass a few options:

php spark db:table my_table --limit-rows 50 --limit-field-value 20 --desc

The option --limit-rows 50 limits the number of rows to 50 rows.

The option --limit-field-value 20 limits the length of the field values to 20 characters, to prevent confusion of the table output in the terminal.

The option --desc sets the sort direction to "DESC".

db:table --metadata

When you have a table named my_table, you can see metadata like the column type, max length of the table with the --metadata option:

php spark db:table my_table --metadata

When using this command it is assumed that the table exists. Otherwise, CodeIgniter will show a table list to select. Also, you can use this command as db:table --metadata.