繁体   English   中英

mysqli DESCRIBE 只返回一行

[英]mysqli DESCRIBE returns only one row

结构:

CREATE TABLE `links` (
 `id` int(11) NOT NULL auto_increment,
 `title` int(11) default NULL,
 `url` varchar(200) NOT NULL,
 `seourl` varchar(150) default NULL,
 `linkset` varchar(50) NOT NULL default 'main',
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

我在这里遇到一个奇怪的问题,查询DESCRIBE links只返回第一行 ( id )。

// my query...
$data = $db->query('DESCRIBE `links`')->fetch();

// query function
public function query($sql, $id = false){
    $this->query_id = mysqli_query($this->connection, $sql);
    if(!$this->query_id){
        psyo::error("Error while executing query (sql: {$sql}).");
        return NULL;
    }else{
        $this->result = mysqli_store_result($this->connection);
        $this->affected = mysqli_affected_rows($this->connection);
        return $id ? $this->query_id : $this;
    }
}

// fetch function
public function fetch($query_id = NULL){
    if($query_id)
        $this->query_id = $query_id;
    if($this->query_id){
        $data = mysqli_fetch_assoc($this->query_id);
    }else{
        psyo::error("Error while fetching results (query id: {$this->query_id}).");
    }
    $this->free();
    return $data;
}

// connection set by
public function connect(){
    $this->connection = mysqli_connect($this->server, $this->username, $this->password, $this->database);
    if(!$this->connection){
        psyo::error("Error connecting to server or while selecting database (database: {$this->database}).");
    }
}

所以这些是我从类中取出的函数(询问是否需要更多......),是的,执行的查询仅返回第一行,但$this->affected在这种情况下返回正确的值5

在 phpMyAdmin 中运行查询时返回预期结果。

可能是什么问题呢?

啊,我自己发现了问题,看起来我的fetch()函数只返回了第一行。 稍微改变一下,它的工作原理:

public function fetch($all = false, $query_id = NULL){
    if($query_id)
        $this->query_id = $query_id;
    if($this->query_id){
        if($all){
            while($row = mysqli_fetch_assoc($this->query_id)){
                $data[] = $row;
            }
        }else{
            $data = mysqli_fetch_assoc($this->query_id);
        }
    }else{
        psyo::error("Error while fetching results (query id: {$this->query_id}).");
    }
    $this->free();
    return $data;
}

该死的那些无心的错误......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM