How to get table structure in CodeIgniter

让人想犯罪 __ 提交于 2019-12-05 04:31:40

Try:

$fields = $this->db->list_fields('table_name');
foreach ($fields as $field)
{
   echo $field;
}

From manual

Omar Alvarado

For more descriptive information, you should use

$fields = $this->db->field_data('table_name');

You're going to get something like this foreach field in fields as stdClass

name = "id"
type = "int"
max_length = 11
default = null
primary_key = 1
Harun Or Rashid

For Get Table Schema in CodeIgniter query:

$query = $this->db->query('SHOW CREATE TABLE yourTableName');
$queryResultArray = $query->result_array();
print_r( $queryResultArray[0]['Create Table'] );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!