Ejemplo n.º 1
0
 /**
  * @param string $host
  * @param string $user
  * @param string $password
  * @param string $dbase
  */
 public function __construct($host = 'localhost', $user = '******', $password = '', $dbase = 'slot-auto')
 {
     MySQLDBase::$instance = $this;
     $this->_host = $host;
     $this->_user = $user;
     $this->_password = $password;
     $this->_dbase = $dbase;
     $this->checkConnection();
     $this->saveToLog();
 }
 public function remove()
 {
     if ($this->_id) {
         $arConds['id'] = $this->_id;
         try {
             $this->_db->delete($this->_tableName, $arConds);
         } catch (Exception $e) {
             echo $e->getMessage();
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
function get_heater_form_content($param)
{
    /*header("HTTP/1.0 500 Internal Server Error", true, 500);
    	print json_encode(array("status"=>"error", "message"=>"it's very bad!"));*/
    if ($param == "material") {
        $table_name = 'alloys';
        $class_name = 'Alloy';
        $conds = array('heater' => array(1));
        $selected_fields = array('id');
    } elseif ($param == "placement") {
        $table_name = 'rad_eff_coef';
        $class_name = 'RadEffCoef';
        $conds = null;
        $selected_fields = array('id');
    }
    try {
        $db = MySQLDBase::instance();
    } catch (Exception $e) {
        //print "Запрос к БД не может быть выполнен. ".$e->getMessage().". Повторите попытку расчета позже";
        print json_encode(array("status" => "db_error", "error_header" => "Ошибка БД", "error_message" => $e->getMessage()));
        // обработка исключения
    }
    $query = getFilterQuery($table_name, $selected_fields, $conds);
    try {
        $rows = $db->select($query);
        foreach ($rows as $row) {
            $ids[] = $row[id];
        }
        //echo "<br>ids: "; print_r($ids); echo "<br>";
        $options = array();
        fillGenericArray($table_name, $class_name, $options, $ids);
        // что будет в случае неудачи?
        if ($param == "placement") {
            $compare_funс = function ($first, $second) {
                if ($first->order == $second->order) {
                    return 0;
                }
                return $first->order < $second->order ? -1 : 1;
            };
            uasort($options, $compare_funс);
        }
        //echo "<br>options: "; print_r($options); echo "<br>";
        foreach ($options as $option) {
            if ($param == "material") {
                // получаем максимальную рабочую температуру нагревателя (наибольшее значение)
                $query = "SELECT MAX(`max_temp`) FROM `max_heater_temp` WHERE `alloy_id` = " . mysql_real_escape_string($option->id);
                $res = $db->select($query);
                //echo "res: "; print_r($res); echo "\n";
                if (empty($res[0]['MAX(`max_temp`)'])) {
                    // если в БД нет максимальной температуры для данного сплава, то не включаем его в список доступных сплавов
                    continue;
                }
                $max_heater_temp = $res[0]['MAX(`max_temp`)'];
                // получаем допустимые значения температуры нагревателя
                $query = "SELECT DISTINCT `temp_heater` FROM `metotech_metalls`.`heater_surface_power` WHERE `temp_heater` <= " . mysql_real_escape_string($max_heater_temp);
                $temps = $db->select($query);
                foreach ($temps as $temp) {
                    $arr[] = $temp['temp_heater'];
                }
                $t_h = getCommaSeparatedList($arr);
                // получаем допустимые значения температуры изделия
                $query = "SELECT DISTINCT `temp_solid` FROM `metotech_metalls`.`heater_surface_power` WHERE `temp_solid` < " . mysql_real_escape_string($max_heater_temp);
                $temps = $db->select($query);
                unset($arr);
                foreach ($temps as $temp) {
                    $arr[] = $temp['temp_solid'];
                }
                $t_s = getCommaSeparatedList($arr);
                //echo "<br>t_s: ".$t_s."<br>";
                $html_code .= "<option value=\"" . $option->id . "\" data-resistivity=\"" . $option->resistivity . "\" data-htemps=\"" . $t_h . "\" data-stemps=\"" . $t_s . "\" data-density=\"" . $option->density . "\">";
                $html_code .= $option->__toString();
                $html_code .= "</option>\n";
                unset($arr);
            } elseif ($param == "placement") {
                $av_coef = ($option->min_coef + $option->max_coef) / 2;
                $html_code .= "<option value=\"" . $av_coef . "\">";
                $html_code .= $option->__toString();
                $html_code .= "</option>\n";
            }
        }
        print $html_code;
    } catch (Exception $e) {
        print json_encode(array("status" => "db_error", "error_header" => "Ошибка БД", "error_message" => $e->getMessage()));
    }
}