字段数据
$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:
如果你的数据库支持,以下数据在这个函数中将是可用的:
- name - 列名称
- max_length - 列的最大长度
- primary_key - 1 如果此列被定义为主键
- type - 指定列的数据类型