Пример #1
0
 public function testDropUsers()
 {
     $result = DB::query('DROP TABLE `users`;');
     $this->assertNotFalse($result, 'drop users failed');
 }
Пример #2
0
     return rtrim($v, 's');
 };
 $fields = DB::select("SELECT * FROM information_schema.COLUMNS WHERE table_schema=DATABASE() and extra != 'auto_increment' and table_name = ?", $table);
 $belongsTo = DB::select("select * from information_schema.KEY_COLUMN_USAGE where referenced_table_name is not null and table_schema=DATABASE() AND table_name = ?", $table);
 $hasMany = DB::select("select * from information_schema.KEY_COLUMN_USAGE where referenced_table_name is not null and table_schema=DATABASE() AND referenced_table_name = ?", $table);
 $hasAndBelongsToMany = DB::select("select * from information_schema.KEY_COLUMN_USAGE a, information_schema.KEY_COLUMN_USAGE b where a.referenced_table_name is not null and b.referenced_table_name is not null and a.table_schema=DATABASE() and b.table_schema=DATABASE() and a.table_name = b.table_name and a.CONSTRAINT_NAME != b.CONSTRAINT_NAME and a.referenced_table_name = ?", $table);
 $findDisplayField = function ($table) {
     $field = DB::selectValue("SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE table_schema=DATABASE() and extra != 'auto_increment' and table_name = ? and COLUMN_NAME = 'name' limit 1", $table);
     if ($field) {
         return $field;
     }
     $field = DB::selectValue("SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE table_schema=DATABASE() and extra != 'auto_increment' and table_name = ? and COLUMN_KEY = 'UNI' limit 1 ", $table);
     if ($field) {
         return $field;
     }
     $field = DB::selectValue("SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE table_schema=DATABASE() and extra != 'auto_increment' and table_name = ? limit 1", $table);
     return $field;
 };
 $findBelongsTo = function ($name) use($belongsTo) {
     foreach ($belongsTo as $relation) {
         if ($relation['KEY_COLUMN_USAGE']['COLUMN_NAME'] == $name) {
             return $relation;
         }
     }
     return false;
 };
 echo $table . '<br/><pre>';
 var_dump($fields[0], $belongsTo, $hasMany, $hasAndBelongsToMany);
 echo '</pre>';
 $dir = 'pages/' . $path . '/' . $table;
 if (!file_exists($dir)) {