Create a Table

@param string  $table         Table name.
@param string  $fields
@param boolean $if_not_exists Check if the table exists.

@return array|bool|mixed|null|void

@uses  PodsData::query

@since 2.0.0
431120
public static function table_create( $table, $fields, $if_not_exists = false ) {

		/**
		 * @var $wpdb wpdb
		 */
		global $wpdb;

		$sql = 'CREATE TABLE';

		if ( true === $if_not_exists ) {
			$sql .= ' IF NOT EXISTS';
		}

		$sql .= " `{$wpdb->prefix}" . self::$prefix . "{$table}` ({$fields})";

		if ( ! empty( $wpdb->charset ) ) {
			$sql .= " DEFAULT CHARACTER SET {$wpdb->charset}";
		}

		if ( ! empty( $wpdb->collate ) ) {
			$sql .= " COLLATE {$wpdb->collate}";
		}

		return self::query( $sql );
	}
190378
public static function field_exists($table, $columns, $db = null)
	{
		if ( ! is_array($columns))
		{
			$columns = array($columns);
		}

		try
		{
			\DB::select_array($columns)->from($table)->limit(1)->execute($db ? $db : static::$connection);
			return true;
		}
		catch (\Database_Exception $e)
		{
			// check if we have a DB connection at all
			$connection = \Database_Connection::instance($db ? $db : static::$connection)->has_connection();

			// if no connection could be made, re throw the exception
			if ( ! $connection)
			{
				throw $e;
			}

			return false;
		}
	}
1037992
public function switchTable($table=null)
	{
		static $tTable;
		if(null===$table)
		{
			if(null!==$tTable)
			{
				$this->table=$tTable;
				$tTable=null;
			}
		}
		else
		{
			$tTable=$this->table;
			$this->table=$table;
		}
		$this->loadFields($this->fields, $this->fieldNames, $this->pk, $this->bitFields);
	}
858199
public function createTable($table, Closure $callback)
    {
    	if($this->hasTable($table)) {
    		return hst_message('is has table');
    	}
        \Schema::connection($this->databaseName)->create($table, $callback);
		return true;
    }
210440
public function createTable($table, $options)
    {
        $table = $this->buildRealTableName($table);
        $sql = $this->getSchema()->getCreateTableSql($table, $options);
        $ret = $this->query($sql);
        return $ret;
    }
517851
public function dropTable($table, $ifExists = true)
    {
        $this->queryBuilder->dropTable($table, $ifExists);
        return $this;
    }
949525
public function exists($table, $column = null)
    {
        $rule = $table;

        // Take any argument after the 2 defined ones
        $args = array_slice(func_get_args(), 2);

        if (isset($column)) {
            $rule .= ",$column";
        }

        if ($args) {
            // Add optional arguments
            foreach ($args as $arg) {
                $rule .= ",$arg";
            }
        }

        $this->addRule("exists:$rule");
        return $this;
    }
553610
public function declareCreation(string $table, array $columns)
    {
        $source = $this->method('up')->getSource();

        $source->addLine("\$this->table('{$table}')");
        foreach ($columns as $name => $type) {
            $source->addLine("    ->addColumn('{$name}', '{$type}')");
        }

        $source->addLine("    ->create();");

        $this->method('down')->getSource()->addString("\$this->table('{$table}')->drop();");
    }
697380
public function addTable($table, $after=null) {

        // Calculate the previous and next tables
        $prevtable = null;
        $nexttable = null;

        if (!$after) {
            if ($this->tables) {
                end($this->tables);
                $prevtable = $this->tables[key($this->tables)];
            }
        } else {
            $prevtable = $this->getTable($after);
        }
        if ($prevtable && $prevtable->getNext()) {
            $nexttable = $this->getTable($prevtable->getNext());
        }

        // Set current table previous and next attributes
        if ($prevtable) {
            $table->setPrevious($prevtable->getName());
            $prevtable->setNext($table->getName());
        }
        if ($nexttable) {
            $table->setNext($nexttable->getName());
            $nexttable->setPrevious($table->getName());
        }
        // Some more attributes
        $table->setLoaded(true);
        $table->setChanged(true);
        // Add the new table
        $this->tables[] = $table;
        // Reorder the whole structure
        $this->orderTables($this->tables);
        // Recalculate the hash
        $this->calculateHash(true);
        // We have one new table, so the structure has changed
        $this->setVersion(userdate(time(), '%Y%m%d', 99, false));
        $this->setChanged(true);
    }
197807
public function update($table, $fieldValues, $conditions, $bind = [])
    {
        if (!$fieldValues) {
            throw new InvalidArgumentException(['Unable to update :table table without data', 'table' => $table]);
        }

        if (is_string($conditions)) {
            $conditions = [$conditions];
        }

        $wheres = [];

        /** @noinspection ForeachSourceInspection */
        foreach ($conditions as $k => $v) {
            if (is_int($k)) {
                $wheres[] = stripos($v, ' or ') ? "($v)" : $v;
            } else {
                $wheres[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $setFields = [];
        foreach ($fieldValues as $k => $v) {
            if (is_int($k)) {
                $setFields[] = $v;
            } elseif ($v instanceof AssignmentInterface) {
                $v->setFieldName($k);
                $setFields[] = $v->getSql();
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $bind = array_merge($bind, $v->getBind());
            } else {
                $setFields[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $sql = 'UPDATE ' . $this->_escapeIdentifier($table) . ' SET ' . implode(',', $setFields) . ' WHERE ' . implode(' AND ', $wheres);

        return $this->_execute('update', $sql, $bind);
    }
294675
function hasFields(model, fields, exists)
{
  if ( isArray( fields ) )
  {
    for (var i = 0; i < fields.length; i++)
    {
      if ( !exists( model[ fields[ i ] ] ) )
      {
        return false;
      }
    }

    return true;
  }
  else // isString( fields )
  {
    return exists( model[ fields ] );
  }
}
848890
protected function createTable(Table $table): void
	{
		$table->addPrimaryKey('id')
			->int()
			->setAutoIncrement();
		$table->addForeignKey('pageId', PagesMapper::class);
		$table->addColumn('name')
			->varChar();
		$table->addColumn('position')
			->int(3);
	}
1191015
public function insert($table, $data)
    {
        $fieldNames = implode(',', array_keys($data));
        $fieldValues = ':'.implode(', :', array_keys($data));

        $query = "INSERT INTO $table ($fieldNames) VALUES($fieldValues)";
        $this->prepare($query);

        /**
         * Iterate through data then bind the values
         */
        foreach ($data as $key => $value) {
            $this->bind(":$key", $value);
        }

        try {
            $this->execute();

            return true;
        } catch (PDOException $e) {
            echo $e->errorInfo[2];

            return false;
        }
    }
577007
public function create($table, $data)
    {
        $query = 'CREATE TABLE IF NOT EXISTS `' . $table . '` (';

        foreach ($data as $column => $value) {
            $query .= $column . ' ' . $value . ', ';
        }

        $query = rtrim(trim($query), ',') . ')'; // Remove final comma

        return $this->query($query);
    }
528538
public function createTable( $table ) {
		$table = $this->safeTable($table);
		$sql = "CREATE TABLE $table ( id INTEGER PRIMARY KEY AUTOINCREMENT ) ";
		$this->adapter->exec( $sql );
	}
584834
public function hasTable($table)
	{
            $sql = $this->grammar->compileTableExists($table);
            $statement = $this->connection->getBatchQuery($sql, []);
            $data = $statement->getResultSet();
            return $data->result()? true: false;
          
	}
692561
public function createTable($table, Table\KeySchema $keySchama, Table\ProvisionedThroughput $provisionedThroughput)
    {
        if (null !== $this->logger) {
            $this->log('Create table '.$table);
        }

        $parameters = array(
            'TableName' => $table,
            'KeySchema' => $keySchama->getForDynamoDB(),
            'ProvisionedThroughput' => $provisionedThroughput->getForDynamoDB()
        );

        if (null !== $this->logger) {
            $this->log('TableCreate request paramaters : '.print_r($parameters, true), Logger::DEBUG);
        }

        $response = $this->connector->createTable($parameters);

        if (null !== $this->logger) {
            $this->log('TableCreate request response : '.print_r($response, true), Logger::DEBUG);
        }
    }