Skip to content

Commit eea28dd

Browse files
authored
Merge pull request #249 from wp-cli/248-skip-column-names
2 parents bda6405 + 694ed4b commit eea28dd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ wp db query [<sql>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [-
342342
Executes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`
343343
and `DB_PASSWORD` database credentials specified in wp-config.php.
344344

345+
Use the `--skip-column-names` MySQL argument to exclude the headers
346+
from a SELECT query. Pipe the output to remove the ASCII table
347+
entirely.
348+
345349
**OPTIONS**
346350

347351
[<sql>]
@@ -364,6 +368,12 @@ Executes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`
364368
# Execute a query stored in a file
365369
$ wp db query < debug.sql
366370

371+
# Query for a specific value in the database (pipe the result to remove the ASCII table borders)
372+
$ wp db query 'SELECT option_value FROM wp_options WHERE option_name="home"' --skip-column-names
373+
+---------------------+
374+
| https://example.com |
375+
+---------------------+
376+
367377
# Check all tables in the database
368378
$ wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);"
369379
+---------------------------------------+-------+----------+----------+

src/DB_Command.php

+10
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ public function cli( $_, $assoc_args ) {
401401
* Executes an arbitrary SQL query using `DB_HOST`, `DB_NAME`, `DB_USER`
402402
* and `DB_PASSWORD` database credentials specified in wp-config.php.
403403
*
404+
* Use the `--skip-column-names` MySQL argument to exclude the headers
405+
* from a SELECT query. Pipe the output to remove the ASCII table
406+
* entirely.
407+
*
404408
* ## OPTIONS
405409
*
406410
* [<sql>]
@@ -423,6 +427,12 @@ public function cli( $_, $assoc_args ) {
423427
* # Execute a query stored in a file
424428
* $ wp db query < debug.sql
425429
*
430+
* # Query for a specific value in the database (pipe the result to remove the ASCII table borders)
431+
* $ wp db query 'SELECT option_value FROM wp_options WHERE option_name="home"' --skip-column-names
432+
* +---------------------+
433+
* | https://example.com |
434+
* +---------------------+
435+
*
426436
* # Check all tables in the database
427437
* $ wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);"
428438
* +---------------------------------------+-------+----------+----------+

0 commit comments

Comments
 (0)