CodeIgniter 中文手册 版本 2.1.0

查看原文

字段数据

$this->db->list_fields()

Returns an array containing the field names. This query can be called two ways:


返回一个包含字段名称的数组。这个查询可以用两种方法调用:

1.您可以将表名称提供给$this->db->list_fields()调用。 $fields = $this->db->list_fields('table_name');

foreach ($fields as $field)
{
   echo $field;
}

2.您可以将组合查询语句传递给query函数执行并返回: $query = $this->db->query('SELECT * FROM some_table');

foreach ($query->list_fields() as $field)
{
   echo $field;
}

$this->db->field_exists()

Sometimes it's helpful to know whether a particular field exists before performing an action. Returns a boolean TRUE/FALSE. Usage example:


执行一个动作前确认字段是否存在时它就变得非常有用了。返回一个布尔值:TRUE/FALSE。实例: if ($this->db->field_exists('field_name', 'table_name'))
{
   // some code...
}

Note: Replace field_name with the name of the column you are looking for, and replace table_name with the name of the table you are looking for.


注解:替换field_name为您要查找人字段名称,同时替换table_name为您要查找表名。

$this->db->field_data()

Returns an array of objects containing field information.


返回一个包含字段名称信息的数组。

Sometimes it's helpful to gather the field names or other metadata, like the column type, max length, etc.


取得字段名称或者其它元数据时就变得非常有用了,例如列的数据类型、最大长度等。

Note: Not all databases provide meta-data.


注解:并非所有数据库都提供元数据。

Usage example:


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

foreach ($fields as $field)
{
   echo $field->name;
   echo $field->type;
   echo $field->max_length;
   echo $field->primary_key;
}

If you have run a query already you can use the result object instead of supplying the table name:


如果您想执行一个已有的查询时你可用返回项替换掉表格名称: $query = $this->db->query("YOUR QUERY");
$fields = $query->field_data();

The following data is available from this function if supported by your database:


如果这个函数支持您的数据库,它将会返回以下数据:

 

最后修改: 2010-10-22 11:24:57