mysql_field_type
(PHP 4, PHP 5)
mysql_field_type — 결과에서 지정된 필드의 유형을 가져옵니다.
경고 이 확장은 PHP 5.5.0에서 더 이상 사용되지 않으며 PHP 7.0.0에서 제거되었습니다. 대신 MySQLi 또는 PDO_MySQL 확장을 사용해야 합니다. MySQL: API 선택 가이드도 참조하세요. 이 함수의 대안은 다음과 같습니다.
- mysqli_fetch_field_direct() [type]
- PDOStatement::getColumnMeta() [driver:decl_type] or [pdo_type]
설명
mysql_field_type(resource $result
, int $field_offset
): string
mysql_field_type()은 mysql_field_name() 함수와 유사합니다. 인수는 동일하지만 필드 유형이 대신 반환됩니다.
매개변수
result
- 평가 중인 결과 리소스입니다. 이 결과는 mysql_query()에 대한 호출에서 비롯됩니다.
field_offset
- 숫자 필드 오프셋입니다.
field_offset
은 0부터 시작합니다.field_offset
이 없으면E_WARNING
수준의 오류도 발생합니다.
반환 값
반환된 필드 유형은 '"int"
, "real"
, "string"
, "blob"
중 하나이며 » MySQL 설명서에 자세히 설명되어 있습니다.
Examples
예제 #1 mysql_field_type() 예제
<?php
mysql_connect("localhost", "mysql_username", "mysql_password");
mysql_select_db("mysql");
$result = mysql_query("SELECT * FROM func");
$fields = mysql_num_fields($result);
$rows = mysql_num_rows($result);
$table = mysql_field_table($result, 0);
echo "Your '" . $table . "' table has " . $fields . " fields and " . $rows . " record(s)\n";
echo "The table has the following fields:\n";
for ($i=0; $i < $fields; $i++) {
$type = mysql_field_type($result, $i);
$name = mysql_field_name($result, $i);
$len = mysql_field_len($result, $i);
$flags = mysql_field_flags($result, $i);
echo $type . " " . $name . " " . $len . " " . $flags . "\n";
}
mysql_free_result($result);
mysql_close();
?>
위의 예는 다음과 유사한 결과를 출력합니다.
Your 'func' table has 4 fields and 1 record(s) The table has the following fields: string name 64 not_null primary_key binary int ret 1 not_null string dl 128 not_null string type 9 not_null enum
노트
참고:
이전 버전과의 호환성을 위해 사용되지 않는 다음 별칭을 사용할 수 있습니다. mysql_fieldtype()
기타
- mysql_field_name() - 결과에서 지정된 필드의 이름을 가져옵니다.
- mysql_field_len() - 지정된 필드의 길이를 반환