Esempio n. 1
0
 /**
  * Extract the primary key of a table.
  *
  * @param \Phinx\Db\Table $table
  * @return string
  */
 public function extractPrimaryKey(\Phinx\Db\Table $table)
 {
     $tableName = $table->getName();
     $databaseName = $this->adapter->getOption('name');
     $query = implode(" ", ['SELECT `COLUMN_NAME`', 'FROM `information_schema`.`COLUMNS`', "WHERE (`TABLE_SCHEMA` = '{$databaseName}')", "AND (`TABLE_NAME` = '{$tableName}')", "AND (`COLUMN_KEY` = 'PRI');"]);
     $result = $this->adapter->query($query);
     if ($result instanceof \PDOStatement) {
         return $result->fetchColumn(0);
     }
     if (is_array($result)) {
         return $result[0];
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Get a single adapter option, or null if the option does not exist.
  *
  * @param  string $name
  * @return mixed
  */
 public function getOption($name)
 {
     return $this->adapter->getOption($name);
 }