Example #1
0
 public function testGet()
 {
     $instance = Db::get($GLOBALS['config_database']);
     $instance2 = Db::get($GLOBALS['config_database']);
     $this->assertEquals($instance, $instance2);
     $instance3 = Db::get($GLOBALS['config_database'], true);
     $this->assertFalse($instance === $instance3);
 }
Example #2
0
 /**
  * Consultar los campos de la tabla en la base de datos
  *
  * @param  string $database base de datos
  * @param  string $table    tabla
  * @param  string $schema   squema
  * @return array
  */
 protected function queryFields($database, $table, $schema = null)
 {
     $sql = $schema ? "DESCRIBE `{$schema}`.`{$table}`" : "DESCRIBE `{$table}`";
     $describe = Db::get($database)->query($sql);
     $fields = array();
     while ($value = $describe->fetch(PDO::FETCH_OBJ)) {
         $fields[$value->Field] = array('Type' => $value->Type, 'Null' => $value->Null != 'NO', 'Key' => $value->Key, 'Default' => $value->Default != '', 'Auto' => $value->Extra == 'auto_increment');
         $this->filterCol($fields[$value->Field], $value->Field);
     }
     return $fields;
 }
Example #3
0
 /**
  * Consultar los campos de la tabla en la base de datos
  *
  * @param  string $database base de datos
  * @param  string $table    tabla
  * @param  string $schema   squema
  * @return array
  */
 protected function queryFields($database, $table, $schema = 'public')
 {
     // Nota: Se excluyen claves compuestas
     $describe = Db::get($database)->query("\n            SELECT DISTINCT\n                c.column_name AS field,\n                c.udt_name AS type,\n                tc.constraint_type AS key,\n                c.column_default AS default,\n                c.is_nullable AS null\n            FROM information_schema.columns c\n            LEFT OUTER JOIN information_schema.key_column_usage cu ON (\n                cu.column_name = c.column_name AND cu.table_name = c.table_name AND (\n                    SELECT COUNT(*) FROM information_schema.key_column_usage\n                    WHERE constraint_name = cu.constraint_name\n                ) = 1)\n            LEFT OUTER JOIN information_schema.table_constraints tc ON (cu.constraint_name = tc.constraint_name AND tc.constraint_type IN ('PRIMARY KEY', 'UNIQUE'))\n            WHERE c.table_name = '{$table}' AND c.table_schema = '{$schema}';\n        ");
     return self::describe($describe);
 }