$database->getPrimaryKey() method

Get column(s) or info for given table’s primary key/index

By default it returns a string with the column name compromising the primary key, i.e. col1. If the primary key is multiple columns then it returns a CSV string, like col1,col2,col3.

If you specify boolean true for the verbose option then it returns an simplified array of information about the primary key. If you specify integer 2 then it returns an array of raw MySQL SHOW INDEX information.

Available since version 3.0.182.


// basic usage
$string = $database->getPrimaryKey(string $table);

// usage with all arguments
$string = $database->getPrimaryKey(string $table, $verbose = false);


verbose (optional)bool, int

Get array of info rather than column(s) string? (default=false)

Return value

string array

$database methods and properties

API reference based on ProcessWire core version 3.0.184

Twitter updates

  • ProcessWire 3.0.185 (dev) core updates, plus new Session Allow module— More
    17 September 2021
  • Three new ProcessWire Textformatter modules: Find/Replace, Markdown in Markup, and Emoji— More
    3 September 2021
  • This week we have a new master version released after a year in the making. With nearly 40 pull requests, hundreds of new additions and more than 100 issue reports resolved, this new version has a ton of great new stuff— More
    27 August 2021

Latest news

  • ProcessWire Weekly #384
    In the 384th issue of ProcessWire Weekly we'll cover the latest core updates, introduce a new module called Session Allow, and highlight a new site of the week. Read on!
    Weekly.pw / 18 September 2021
  • ProcessWire 3.0.184 new master/main version
    This week we have a new master/main version released after a full year in the making. As you might imagine, this new version has a ton of great new stuff and we’ll try to cover much of it here.
    Blog / 27 August 2021
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer