mysql_fetch_field结果中“type”的可能值

时间:2013-09-08 18:50:03

标签: php

调用mysql_fetch_field时,结果有一个名为“type”的属性。我看到像“字符串”这样的东西,它是一种PHP类型,但也是“blob”,这是一种MySQL类型。是否存在此函数返回的可能类型的权威和详尽列表?

PHP文档充其量是模糊的。我需要知道我正在涵盖所有可能性。我确实设法为http://www.php.net/manual/en/function.mysql-field-type.php找到了一些更好的文档:“返回的字段类型将是”int“,”real“,”string“,”blob“和其他...”

它指向MySQL文档。在那里,它似乎要我开始查看C头文件,因为它所说的是“当前列的MYSQL_FIELD结构”。

3 个答案:

答案 0 :(得分:1)

来自here

blob - 包含或返回二进制长对象的表达式的列。这包括所有BLOB或TEXT类型列。

日期 - 日期栏。返回日期值的表达式的类型为int,real,orstring,具体取决于返回的值。

datetime - DATETIME列。返回datetime值的表达式的类型为int,real,orstring,具体取决于返回的值。

int - 包含返回整数数据的列或表达式。这包括所有INT类型列。

null - 返回NULL的表达式。

real - 包含返回浮点数的列或表达式。这包括DECIMAL,FLOAT和DOUBLE列类型。

string - CHAR,ENUM,SET或VARCHAR列,或返回字符数据的表达式。

注意:
即使表达式返回的字符数超过CHAR / VARCHAR列的最大长度255个字符,返回的类型也是字符串而不是blob,正如您所料。

时间 - 时间列。返回时间值的表达式的类型为real或string,具体取决于返回的值。

timestamp - TIMESTAMP列。返回时间戳值的表达式的类型为int。

年 - 年度专栏。返回年份值的表达式的类型为int。

unknown - 与mysql_fetch_field()已知的任何类型都不匹配的类型。这种类型的出现可能表明MySQL的版本比PHP版本更新。


这里是Zak Greant编辑的“PHP Functions Essential Reference”一书 from the book PHP Functions Essential Reference edited by Zak Greant

答案 1 :(得分:0)

请参阅http://php.net/manual/en/function.mysql-fetch-field.php,其中提供了一些有用的信息。我认为类型只是常见的类型,如int,float,string或blob。

答案 2 :(得分:0)

取自PHP:http://php.net/manual/en/mysqli.constants.php#constantmysqli-group-flag

0    MYSQLI_TYPE_DECIMAL: Field is defined as DECIMAL
1    MYSQLI_TYPE_CHAR: Field is defined as TINYINT. For CHAR, see MYSQLI_TYPE_STRING
2    MYSQLI_TYPE_SHORT: Field is defined as SMALLINT
3    MYSQLI_TYPE_LONG: Field is defined as INT
4    MYSQLI_TYPE_FLOAT: Field is defined as FLOAT
5    MYSQLI_TYPE_DOUBLE: Field is defined as DOUBLE
6    MYSQLI_TYPE_NULL: Field is defined as DEFAULT NULL
7    MYSQLI_TYPE_TIMESTAMP: Field is defined as TIMESTAMP
8    MYSQLI_TYPE_LONGLONG: Field is defined as BIGINT
9    MYSQLI_TYPE_INT24: Field is defined as MEDIUMINT
10   MYSQLI_TYPE_DATE: Field is defined as DATE
11   MYSQLI_TYPE_TIME: Field is defined as TIME
12   MYSQLI_TYPE_DATETIME: Field is defined as DATETIME
13   MYSQLI_TYPE_YEAR: Field is defined as YEAR
14   MYSQLI_TYPE_NEWDATE: Field is defined as DATE
16   MYSQLI_TYPE_BIT: Field is defined as BIT (MySQL 5.0.3 and up)
246  MYSQLI_TYPE_NEWDECIMAL: Precision math DECIMAL or NUMERIC field (MySQL 5.0.3 and up)
247  MYSQLI_TYPE_ENUM: Field is defined as ENUM
248  MYSQLI_TYPE_SET: Field is defined as SET
249  MYSQLI_TYPE_TINY_BLOB: Field is defined as TINYBLOB
250  MYSQLI_TYPE_MEDIUM_BLOB: Field is defined as MEDIUMBLOB
251  MYSQLI_TYPE_LONG_BLOB: Field is defined as LONGBLOB
252  MYSQLI_TYPE_BLOB: Field is defined as BLOB
253  MYSQLI_TYPE_VAR_STRING: Field is defined as VARCHAR
254  MYSQLI_TYPE_STRING: Field is defined as CHAR or BINARY
255  MYSQLI_TYPE_GEOMETRY: Field is defined as GEOMETRY