API15

JDatabaseMySQLi/getTableFields

From Joomla! Documentation

< API15:JDatabaseMySQLi
Revision as of 17:15, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Retrieves information about the given tables <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JDatabaseMySQLi/getTableFields|Edit De...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Retrieves information about the given tables

[Edit Descripton]

Template:Description:JDatabaseMySQLi/getTableFields

Syntax[edit]

getTableFields($tables, $typeonly=true)
Parameter Name Default Value Description
$tables A table name or a list of table names
$typeonly true Only return field types, default true

Returns[edit]

array An array of fields by table

Defined in[edit]

libraries/joomla/database/database/mysqli.php

Importing[edit]

jimport( 'joomla.database.database.mysqli' );

Source Body[edit]

function getTableFields( $tables, $typeonly = true )
{
        settype($tables, 'array'); //force to array
        $result = array();

        foreach ($tables as $tblval)
        {
                $this->setQuery( 'SHOW FIELDS FROM ' . $tblval );
                $fields = $this->loadObjectList();

                if($typeonly)
                {
                        foreach ($fields as $field) {
                                $result[$tblval][$field->Field] = preg_replace("/[(0-9)]/",'', $field->Type );
                        }
                }
                else
                {
                        foreach ($fields as $field) {
                                $result[$tblval][$field->Field] = $field;
                        }
                }
        }

        return $result;
}

[Edit See Also] Template:SeeAlso:JDatabaseMySQLi/getTableFields

Examples[edit]

<CodeExamplesForm />