Changeset 4367 for trunk/include/dblayer/functions_mysql.inc.php
- Timestamp:
- Nov 25, 2009, 8:02:57 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/dblayer/functions_mysql.inc.php
r4335 r4367 22 22 // +-----------------------------------------------------------------------+ 23 23 24 define('DB_ENGINE', 'MySQL'); 25 26 define('DB_REGEX_OPERATOR', 'REGEXP'); 27 define('DB_RANDOM_FUNCTION', 'RAND'); 28 24 29 /** 25 30 * … … 106 111 107 112 return $result; 113 } 114 115 function pwg_db_nextval($column, $table) 116 { 117 $query = ' 118 SELECT IF(MAX('.$column.')+1 IS NULL, 1, MAX('.$column.')+1) 119 FROM '.$table; 120 list($next) = pwg_db_fetch_row(pwg_query($query)); 121 122 return $next; 108 123 } 109 124 … … 444 459 } 445 460 461 function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE') 462 { 463 if ($date!='CURRENT_DATE') 464 { 465 $date = '\''.$date.'\''; 466 } 467 468 return 'SUBDATE('.$date.',INTERVAL '.$period.' DAY)'; 469 } 470 471 function pwg_db_get_recent_period($period, $date='CURRENT_DATE') 472 { 473 $query = ' 474 SELECT '.pwg_db_get_recent_period_expression($period); 475 list($d) = pwg_db_fetch_row(pwg_query($query)); 476 477 return $d; 478 } 479 480 /** 481 * returns an array containing the possible values of an enum field 482 * 483 * @param string tablename 484 * @param string fieldname 485 */ 486 function get_enums($table, $field) 487 { 488 // retrieving the properties of the table. Each line represents a field : 489 // columns are 'Field', 'Type' 490 $result = pwg_query('desc '.$table); 491 while ($row = pwg_db_fetch_assoc($result)) 492 { 493 // we are only interested in the the field given in parameter for the 494 // function 495 if ($row['Field'] == $field) 496 { 497 // retrieving possible values of the enum field 498 // enum('blue','green','black') 499 $options = explode(',', substr($row['Type'], 5, -1)); 500 foreach ($options as $i => $option) 501 { 502 $options[$i] = str_replace("'", '',$option); 503 } 504 } 505 } 506 pwg_db_free_result($result); 507 return $options; 508 } 509 510 // get_boolean transforms a string to a boolean value. If the string is 511 // "false" (case insensitive), then the boolean value false is returned. In 512 // any other case, true is returned. 513 function get_boolean( $string ) 514 { 515 $boolean = true; 516 if ( 'false' == strtolower($string) ) 517 { 518 $boolean = false; 519 } 520 return $boolean; 521 } 522 523 /** 524 * returns boolean string 'true' or 'false' if the given var is boolean 525 * 526 * @param mixed $var 527 * @return mixed 528 */ 529 function boolean_to_string($var) 530 { 531 if (is_bool($var)) 532 { 533 return $var ? 'true' : 'false'; 534 } 535 else 536 { 537 return $var; 538 } 539 } 540 446 541 // my_error returns (or send to standard output) the message concerning the 447 542 // error occured for the last mysql query.
Note: See TracChangeset
for help on using the changeset viewer.