字段數(shù)據(jù)
$this->db->list_fields()
Returns an array containing the field names. This query can be called two ways:
返回一個(gè)包含字段名稱的數(shù)組。這個(gè)查詢可以用兩種方法調(diào)用:
1.您可以將表名稱提供給$this->db->list_fields()調(diào)用。
$fields = $this->db->list_fields('table_name');
foreach ($fields as $field)
{
???echo $field;
}
2.您可以將組合查詢語(yǔ)句傳遞給query函數(shù)執(zhí)行并返回:
$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:
執(zhí)行一個(gè)動(dòng)作前確認(rèn)字段是否存在時(shí)它就變得非常有用了。返回一個(gè)布爾值:TRUE/FALSE。實(shí)例:
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為您要查找人字段名稱,同時(shí)替換table_name為您要查找表名。
$this->db->field_data()
Returns an array of objects containing field information.
返回一個(gè)包含字段名稱信息的數(shù)組。
Sometimes it's helpful to gather the field names or other metadata, like the column type, max length, etc.
取得字段名稱或者其它元數(shù)據(jù)時(shí)就變得非常有用了,例如列的數(shù)據(jù)類型、最大長(zhǎng)度等。
Note: Not all databases provide meta-data.
注解:并非所有數(shù)據(jù)庫(kù)都提供元數(shù)據(jù)。
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:
如果您想執(zhí)行一個(gè)已有的查詢時(shí)你可用返回項(xiàng)替換掉表格名稱:
$query = $this->db->query("YOUR QUERY");
$fields = $query->field_data();
The following data is available from this function if supported by your database:
如果這個(gè)函數(shù)支持您的數(shù)據(jù)庫(kù),它將會(huì)返回以下數(shù)據(jù):
- name - 列名稱
- max_length - 列的最大長(zhǎng)度
- primary_key - 1 如果此列被定義為主鍵
- type - 指定列的數(shù)據(jù)類型
?