Changeset 497 for trunk/lib/DB.inc.php
- Timestamp:
- Sep 15, 2014 9:44:27 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/DB.inc.php
r484 r497 441 441 } 442 442 443 /** 444 * Returns the values of an ENUM or SET column, returning them as an array. 445 * 446 * @param string $db_table database table to lookup 447 * @param string $db_col database column to lookup 448 * @param bool $sort Sort the output. 449 * @return array Array of the set/enum values on success, false on failure. 450 */ 451 public function getEnumValues($db_table, $db_col, $sort=false) 452 { 453 $app =& App::getInstance(); 454 455 $qid = $this->query("SHOW COLUMNS FROM " . $this->escapeString($db_table) . " LIKE '" . $this->escapeString($db_col) . "'", false); 456 457 $row = mysql_fetch_row($qid); 458 if (preg_match('/^enum|^set/i', $row[1]) && preg_match_all("/'([^']*)'/", $row[1], $matches)) { 459 if ($sort) { 460 natsort($matches[1]); 461 } 462 return $matches[1]; 463 } else { 464 $app->logMsg(sprintf('No set or enum fields found in %s.%s', $db_table, $db_col), LOG_ERR, __FILE__, __LINE__); 465 return false; 466 } 467 } 468 469 443 470 } // End. 444 471
Note: See TracChangeset
for help on using the changeset viewer.