Name

mysql_field_type

Synopsis

string mysql_field_type(qresource query, int attribute)

Returns the PHP type of an attribute. The first parameter is a query resource handle returned from a prior call to mysql_list_fields( ), mysql_query( ), or mysql_unbuffered_query( ). The second argument is the ordinal number of the attribute in the SQL query, where zero refers to the first attribute.

Example

<?php
  $query = "SELECT * FROM presents, people WHERE presents.people_id = people.people_id";
  
  $connection = mysql_connect("localhost", "fred", "shhh");
  mysql_select_db("wedding", $connection);
  
  $result = mysql_query($query, $connection);
  
  for($x=0;$x<mysql_num_fields($result);$x++)
     echo "The type of attribute $x is " . mysql_field_type($result, $x) . "\n";
?>

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.