Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2013
    Posts
    47
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Metadata missing the Primary Key

    Hello everyone,

    Not sure if this should be posted in PHP or MySQL but here it is.

    I have a working DB and PHP program that has a very minor snafu. This code is designed to get the maximum field lengths from metadata and does just that.... except that the primary key field (first field in table) is omitted and I have no idea why.

    My code is broken up into subroutines so it's difficult to put it in a single coherent piece, so here are a few snippets. If you need more, let me know.

    Code:
    	$fieldList=$library->getFields(&$mysqli,&$stmt,$fieldCount);  
            echo "<b>fieldList: </b>";var_dump($fieldList);echo "<br /><br />";
    Code:
     
    function getFields(&$mysqli,&$stmt)
    {
    	$fieldList = array();
    	$meta = $stmt->result_metadata();  
        while ( $field = $meta->fetch_field() ) 
    		{  
      		$fieldList[] = $field->name;   
    		}
    	return $fieldList;
    }
    -- Displays all fields


    Code:
    while ( $field = $meta->fetch_field() )
    	{
    		echo "<b>MetaData Fields:</b> <pre>"; print_r($field);echo "</pre>";   
             }
    -- Displays all fields except the primary key field.
    Last edited by geno11x11; 03-05-2014 at 08:07 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    How are you going abouts swapping these to test them? We need to see that. The signature you have here for the method doesn't match the call, is this the same method? Otherwise, the $fieldCount has no use since there is no call to a func_get_arg[s] method. The code used to create the statements including the SQL would help as well.

    Also, don't pass the connection or statement by reference either in the method signature nor in the call (do not do this at all; call time pass-by-reference is long deprecated). In PHP 5.0+ the objects are by default passed by an object pointer so the changes will already reflect the core object. The only gain by using a reference would be in regards to destruction.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •