Example #1
0
function articles_new($link, $title, $date, $content, $id_category)
{
    $title = trim($title);
    if ($title == '') {
        return false;
    }
    $t = "INSERT INTO articles (title, date, content, categories_id)  VALUES ('%s', '%s', '%s', '%d')";
    $query = sprintf($t, mysqli_real_escape_string($link, $title), $date, $content, (int) $id_category);
    $result = mysqli_query($link, $query);
    if (!$result) {
        die(mysqli_error($link));
    }
    return get_last_insert_id($link);
}
Example #2
0
function insert_array_db($table, $arr_columns, $return_id = false)
{
    global $conex;
    $columns = '(' . implode_keys(', ', $arr_columns) . ')';
    $values = '(\'' . implode('\', \'', $arr_columns) . '\')';
    $sql = 'INSERT INTO ' . $table . $columns . ' VALUES ' . $values;
    $insert = my_query($sql, $conex);
    if ($return_id && $insert) {
        return get_last_insert_id($conex);
    } elseif ($insert) {
        return true;
    } else {
        return false;
    }
}
Example #3
0
 public static function addToDb($worksheet, $lab_config)
 {
     if ($worksheet == null || $lab_config == null) {
         return;
     }
     $saved_db = DbUtil::switchToLabConfig($lab_config->id);
     $margins_csv = implode(",", $worksheet->margins);
     $id_fields_csv = implode(",", $worksheet->idFields);
     $query_string = "INSERT INTO worksheet_custom (name, header, footer, title, margins, id_fields, p_fields, s_fields, t_fields, p_custom, s_custom) " . "VALUES ('{$worksheet->name}', '{$worksheet->headerText}', '{$worksheet->footerText}', '{$worksheet->titleText}', '{$margins_csv}', '{$id_fields_csv}', '', '', '', '', '')";
     query_insert_one($query_string);
     $worksheet_id = get_last_insert_id();
     foreach ($worksheet->columnWidths as $key => $value) {
         $test_type_id = $key;
         $width_list = $value;
         foreach ($width_list as $key2 => $value2) {
             $measure_id = $key2;
             $width = $value2;
             $query_string = "INSERT INTO worksheet_custom_test (worksheet_id, test_type_id, measure_id, width) " . "VALUES ({$worksheet_id}, {$test_type_id}, {$measure_id}, '{$width}')";
             query_insert_one($query_string);
         }
     }
     foreach ($worksheet->userFields as $field_entry) {
         $field_name = $field_entry[1];
         $field_width = $field_entry[2];
         $query_string = "INSERT INTO worksheet_custom_userfield (worksheet_id, name, width) " . "VALUES ({$worksheet_id}, '{$field_name}', {$field_width}) ";
         query_insert_one($query_string);
     }
     $retval = $worksheet_id;
     DbUtil::switchRestore($saved_db);
     return $worksheet_id;
 }
Example #4
0
 public function create($lab_config_id)
 {
     $amount = $this->amount;
     $billId = $this->billId;
     $query_string = "INSERT INTO `payments` (`amount`, `bill_id`)\r\n\t\t\t\t\t\t\tVALUES ({$amount}, {$billId})";
     $saved_db = DbUtil::switchToLabConfig($lab_config_id);
     query_insert_one($query_string);
     $this->id = get_last_insert_id();
     DbUtil::switchRestore($saved_db);
     return 1;
 }