PHP Method Schema::execute, someline-starter Code Examples

This page contains top rated real world PHP examples of method Schema::execute from package someline-starter extracted from open source projects. You can rate examples to help us improve the quality of examples
Frequently Used Methods
Example #1
Show file File: DBUtil.php Project: acmadi/diantaksi
0
 /**
  * Make a table.
  *
  * @param   string  $table
  * @param   array   $columns
  * @return  void
  */
 public static function make($table, $columns, $connection = null)
 {
     // check exists
     if (static::exists($table)) {
         // error
         trigger_error('Table already exists.');
         // return
         return false;
     }
     // Laravel provides a mechanism for building tables,
     // but only in the context of migrations which are run
     // at the command line.  The following is a makeshift
     // way of achieving the same thing using the same methods.
     // NOTE: I don't know how to make this work w/ a custom
     // connection.  Only working w/ default connection.
     $db = new \Laravel\Database\Schema\Table($table);
     $db->create();
     // for each column...
     foreach ($columns as $column) {
         // The makeup of the $columns array is to define
         // each field w/ the name as the key, and the
         // value containing both a type and a length.
         $type = $column['type'];
         $field = isset($column['field']) ? $column['field'] : null;
         $length = isset($column['length']) ? $column['length'] : null;
         // add to schema
         $db->{$type}($field, $length);
         // if index...
         if (isset($column['index'])) {
             if ($column['index'] == true) {
                 $db->index($field);
             }
         }
     }
     // execute
     \Schema::execute($db);
 }
Example #2
Show file File: CSV.php Project: alexdiasgonsales/organizador
0
 /**
  * Convert CSV to database table.
  *
  * @param   string  $table
  * @param   boolean  $table_already_exists
  * @param   boolean  $clear_existing_records
  * @return  void
  */
 public function to_database($table = null, $table_already_exists = false, $clear_existing_records = false)
 {
     // if no pre-existing table defined...
     if (!$table_already_exists) {
         $t = new \Table($table);
         $t->create();
         foreach ($this->columns as $column) {
             // create column; default length is 200
             $t->string($column);
         }
         \Schema::execute($t);
     } else {
         // if clear existing records...
         \DB::query(sprintf("TRUNCATE TABLE `%s`", $table));
     }
     // foreach row...
     foreach ($this->rows as $value) {
         // add to table
         \DB::table($table)->insert($value);
     }
 }