示例#1
0
 /**
  * 读取表字段信息
  *
  * @param string $tableName 表名称
  *
  * @return boolean|array
  *
  * 返回结果结构如下:
  * array(
  *      'pri_name'      =>string,
  *      'pri_is_auto'   =>boolean,
  *      'fields_default'=>array,
  *      'fields_type'   =>array,
  * );
  */
 public function getTableMate($tableName)
 {
     if (empty($tableName)) {
         return false;
     }
     $sql = 'PRAGMA table_info({:' . $tableName . ':})';
     if (!$this->query($sql)->isSuccess()) {
         return false;
     }
     $tableMate = $this->stmt->fetchAll();
     $mate['pri_name'] = null;
     $mate['pri_is_auto'] = false;
     foreach ($tableMate as $field) {
         $mate['fields_default'][$field['name']] = $field['dflt_value'];
         $mate['fields_type'][$field['name']] = $field['type'];
         if ($field['pk']) {
             $mate['pri_name'] = $field['name'];
             $mate['pri_is_auto'] = true;
         }
     }
     return $mate;
 }
示例#2
0
 /**
  * 读取表字段信息
  *
  * @param string $tableName 表名称
  *
  * @return boolean|array
  *
  * 返回结果结构如下:
  * array(
  *      'pri_name'      =>string,
  *      'pri_is_auto'   =>boolean,
  *      'fields_default'=>array,
  *      'fields_type'   =>array,
  * );
  */
 public function getTableMate($tableName)
 {
     if (empty($tableName)) {
         return false;
     }
     $sql = 'SHOW COLUMNS FROM {:' . $tableName . ':}';
     if (!$this->query($sql)->isSuccess()) {
         return false;
     }
     $tableMate = $this->stmt->fetchAll();
     $mate['pri_name'] = null;
     $mate['pri_is_auto'] = false;
     foreach ($tableMate as $field) {
         $mate['fields_default'][$field['Field']] = $field['Default'];
         $mate['fields_type'][$field['Field']] = $field['Type'];
         if ($field['Key'] == 'PRI') {
             $mate['pri_name'] = $field['Field'];
             $mate['pri_is_auto'] = $field['Extra'] == 'auto_increment';
         }
     }
     return $mate;
 }