Sqlite 操作数据库

3.2.3版本的Sqlite数据库无法获取字段信息,导致操作数据库失败

public function getFields($tableName) {

list($tableName) = explode(' ', $tableName);
$result =   $this->query('PRAGMA table_info( '.$tableName.' )');
$info   =   array();
if($result){
    foreach ($result as $key => $val) {
        $name = isset($val['field']) ? $val['field'] : $val['name'];
        $info[$name] = array(
            'name'    => $name,
            'type'    => $val['type'],
            'notnull' => (bool)(((isset($val['null'])) && ($val['null'] === '')) || ((isset($val['notnull'])) && ($val['notnull'] === ''))), // not null is empty, null is yes
            'default' => isset($val['default']) ? $val['default'] : (isset($val['dflt_value'])?$val['dflt_value']:""),
            'primary' => isset($val['key']) ? strtolower($val['key']) == 'pri' : (isset($val['pk']) ? $val['pk'] : false),
            'autoinc' => isset($val['extra']) ? strtolower($val['extra']) == 'auto_increment' : (isset($val['key']) ? $val['key'] : false),
        );
    }
}
return $info;

}

赞(0) 打赏
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

    暂无评论...