thinkphp Get the field name, is there a simpler way?

Source: Internet
Author: User
Thinkphp 3.2

$use=D('classone');$db=$use->select(5);$arr = $db[0] ? $db[0] : '';foreach($arr as $key => $value){       $arrKey[] =  $key;}

This, I took the name of the field to get into an array $arrKey, but I think this method is rather stupid, there should be a direct access to the method, I ask there is no???

Reply content:

Thinkphp 3.2

$use=D('classone');$db=$use->select(5);$arr = $db[0] ? $db[0] : '';foreach($arr as $key => $value){       $arrKey[] =  $key;}

This, I took the name of the field to get into an array $arrKey, but I think this method is rather stupid, there should be a direct access to the method, I ask there is no???

Tp5?

/** * Get data table information * @access public * @param string $tableName data table name empty automatically get * @param string $fetch get information types including fie LDS type bind PK * @return Mixed */Public function gettableinfo ($tableName = ', $fetch = ') {stat        IC $_info = [];        if (! $tableName) {$tableName = $this->gettable ();        } if (Is_array ($tableName)) {$tableName = key ($tableName)?: current ($tableName);        } if (Strpos ($tableName, ', ')) {//Multiple tables do not get field information return false;        } $GUID = MD5 ($tableName);            if (!isset ($_info[$guid])) {$info = $this->connection->getfields ($tableName);            $fields = Array_keys ($info);            $bind = $type = [];                foreach ($info as $key = + $val) {//record field type $type [$key] = $val [' type ']; if (Preg_match ('/(int|double|float|decimal|real|numeric|serial)/is ', $val [' type '])) {$bind [$Key] = PDO::P aram_int;                } elseif (Preg_match ('/bool/is ', $val [' type '])) {$bind [$key] = PDO::P aram_bool;                } else {$bind [$key] = PDO::P aram_str;                } if (!empty ($val [' primary '])) {$PK [] = $key;            }} if (Isset ($PK)) {//Set Primary KEY $PK = count ($PK) > 1? $PK: $pk [0];            } else {$pk = null;            } $result = [' Fields ' + $fields, ' type ' and ' $type, ' bind ' = ' $bind, ' PK ' + $PK];        $_info[$guid] = $result; } return $fetch?    $_info[$guid] [$fetch]: $_info[$guid]; }

Summarize thinkphp Quick Query Getby, GetField, Getfieldby usage and scenes http://baijunyao.com/article/59

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.