DB::MySQL function tableInfo

From: Date: Mon, 10 Jun 2002 14:05:31 +0000
Subject: DB::MySQL function tableInfo
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6884@lists.php.net to get a copy of this message
here is just another change i did to mysql.php, because i needed more info than returned by the php mysqlfunctions. Perhaps, it could be used. function tableInfo($result, $mode = null) { $count = 0; $id = 0; $res = array(); if (is_string($result)) { $id = @mysql_list_fields($this->dsn['database'], $result, $this->connection); if (empty($id)) { return $this->mysqlRaiseError(); } } else { // else we want information about a resultset $id = $result; if (empty($id)) { return $this->mysqlRaiseError(); } } $count = @mysql_num_fields($id); $info_query = $this->query("show fields from $result"); $i=0; while ($row = $info_query->fetchRow(DB_FETCHMODE_OBJECT)) { $res['num_fields']= $count; $res[$i]['table'] = $result; $res[$i]['name'] = $row->Field; ereg("([a-zA-Z ]*)\(?([a-zA-Z0-9,']*)\)?[ ]?(unsigned)?[ ]?(zerofill)?",$row ->Type,$type); $res[$i]['type'] = $type[1]; if ($type[1]=='set' || $type[1]=='enum') { $res[$i]['values'] = $type[2]; } $res[$i]['len'] = @mysql_field_len($id, $i); $res[$i]['not_null'] = ($row->Null != 'YES') ? TRUE : FALSE; $res[$i]['primary_key'] = ($row->Key == 'PRI') ? TRUE : FALSE; $res[$i]['mutliple_key'] = ($row->Key == 'MUL') ? TRUE : FALSE; $res[$i]['default'] = $row->Default; $res[$i]['auto_increment'] = ($row->Extra == 'auto_increment') ? TRUE : FALSE; $res[$i]['unsigned'] = ($type[3] == 'unsigned') ? TRUE : FALSE; $res[$i]['zerofill'] = ($type[4] == 'zerofill') ? TRUE : FALSE; $res[$i]['extra'] = $row->Extra; $res[$i]['flags'] = @mysql_field_flags ($id, $i); if (!empty($mode)) { if ($mode & DB_TABLEINFO_ORDER) { $res['order'][$res[$i]['name']] = $i; } if ($mode & DB_TABLEINFO_ORDERTABLE) { $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i; } } $i++; } // free the result only if we were called on a table if (is_string($result)) { @mysql_free_result($id); } return $res; } And btw, great work the whole PEAR system. cya, uli. _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com

« previous php.pear.dev (#6884) next »