Exemple #1
0
 public function testSelectPosts()
 {
     $result = DB::select("SELECT * FROM `posts`;");
     $this->assertEquals(2, count($result));
     $this->assertEquals('posts', array_shift(array_keys($result[0])));
     $this->assertEquals('id', array_shift(array_keys(array_shift($result[0]))));
     $result = DB::select("SELECT * FROM `posts`, `users` WHERE posts.user_id = users.id and users.username = '******';");
     $this->assertEquals(2, count($result));
     $this->assertEquals(array('posts', 'users'), array_keys($result[0]));
     $this->assertEquals('id', array_shift(array_keys($result[0]['posts'])));
     $this->assertEquals('test1', $result[0]['users']['username']);
     $this->setExpectedException('MindaPHP\\DBError');
     $result = DB::select("some bogus query;");
 }
Exemple #2
0
    echo '</form>';
    var_dump($entities);
} else {
    foreach ($tables as $table) {
        $path = 'admin2';
        $pages = array('index().php', 'index(admin).phtml', 'add().php', 'add(admin).phtml', 'edit($id).php', 'edit(admin).phtml', 'delete($id).php', 'delete(admin).phtml', 'view($id).php', 'view(admin).phtml');
        $humanize = function ($v) {
            return str_replace('_', ' ', $v);
        };
        $singularize = function ($v) {
            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) {