mysql_field_type
(PHP 3, PHP 4 )
mysql_field_type --
Pobiera typ podanego pola
Opis
string
mysql_field_type ( resource wynik, int ofset_pola)
Funkcja mysql_field_type() jest podobna do
mysql_field_name(). Argumenty są identyczne,
ale zwracany jest typ pola. Będzie to jeden z "int", "real",
"string", "blob" lub innych opisanych w dokumentacji
MySQL.
Przykład 1. Typy pól MySQL <?php
mysql_connect('localhost','uzytkownik','haslo');
mysql_select_db('baza');
$result = mysql_query('SELECT * FROM tabela');
$fields = mysql_num_fields($result);
$rows = mysql_num_rows($result);
$table = mysql_field_table($result, 0);
echo "Tabela '".$table."' ma ".$fields." pól i ".$rows." wierszy\n";
echo "Tabela ma następujące pola:\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";
$i++;
}
mysql_free_result($result);
mysql_close();
?> |
Powyższy przykład da następujący wynik:
Tabela 'tabela' ma 4 pól i 1 wierszy
Tabela ma następujące pola:
string name 64 not_null primary_key binary
int ret 1 not_null
string dl 128 not_null
string type 9 not_null enum |
|
Aby zachować zgodność z poprzednimi wersjami, można użyć również
mysql_fieldtype(). Jest to jednak niezalecane.