简体   繁体   English

如何在CodeIgniter中获取表结构

[英]How to get table structure in CodeIgniter

I want to know the structure of a table. 我想知道一个表的结构。 How I can do it in CodeIgniter. 我怎么能在CodeIgniter中做到这一点。 Using database class I got 'Invalid SQL Statement' error when I ran $this->db->query('desc mytable'); 使用数据库类我运行$this->db->query('desc mytable');时出现“无效的SQL语句”错误$this->db->query('desc mytable');

Try: 尝试:

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

From manual 手册

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 你将在字段中获得类似stdClass的foreach字段

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

For Get Table Schema in CodeIgniter query: 对于CodeIgniter查询中的获取表模式:

$query = $this->db->query('SHOW CREATE TABLE yourTableName');
$queryResultArray = $query->result_array();
print_r( $queryResultArray[0]['Create Table'] );

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

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