This is a part of my code for my data interfacer class which takes an SQL
RESULT RESOURCE and gets the field from it. Problem is, i can't get the
primary key out nor the auto-increment flag out. Before, the same script (or
so, it was modified but not that part) was working fine. I tried it on
several tables and on several database servers and i still can't get the
PRIMARY or AUTO_INCREMENT flag out. In fact the only flag that is returned
is: NOT_NULL. (When i ECHO the mysql_field_flags(...) i get only notnull).

Furthermore, i can't seem to get the data, that i will check more in detail,
my most important part IS the primary and auto-increment flags.

Thanks in advance if you can find something.

Here is the complete code that you need:

//Execute the query twice to get the fields and a result for the values
$result =
, 1);
$fieldlist =
, 1);

//get the first row to insert values in the interface
$data = mysql_fetch_array($result);

//Used for the field flag fetching
$curfield = -1;
$fieldcount = mysql_num_fields($fieldlist);

//Loop the data field definition and add the field in the end
for($curfield = 0; $curfield < $fieldcount; $curfield++){
   //Get the current field
   $datadef = mysql_fetch_field($fieldlist, $curfield);

   //Reset the data
   $primary_key = 0;
   $auto_increment = 0;

   //Get all the other params from the field definition
   $fieldname = $datadef->name;
   $sourcetable  = $datadef->table;
   $datatype = constant("MYSQL_NDT_" . strtoupper($datadef->type));
   $fieldvalue = $data[$datadef->name];
   $datasize = $datadef->max_length;

   //Get the field flags and explode them immediatly
   $fieldflags = explode(" ", mysql_field_flags($fieldlist, $curfield));

   //Check all the field flags
   foreach($fieldflags as $key => $value){
    if($value == "primary_key"){
     $primary_key = 1;
    }elseif($value == "auto_increment"){
     $auto_increment = 1;

   //Add the field to the data_interface
   $newint->add_field($fieldname, $fieldvalue, $datatype, $datasize,
$primary, $autoinc, $sourcetable);

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to