UpdateRows() public method

Updates rows in a table based on a WHERE filter (can be just one or many rows based on the filter)
public UpdateRows ( string $tableName, array $valuesArray, array $whereArray = null ) : boolean
$tableName string The name of the table
$valuesArray array An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, ect)
$whereArray array (Optional) An associative array containing the column names as keys and values as data. The values must be SQL ready (i.e. quotes around strings, formatted dates, ect). If not specified then all values in the table are updated.
return boolean Returns TRUE on success or FALSE on error
Ejemplo n.º 1
0
function admin_cp_newpw()
{
    global $hmuser;
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('newpw_checkkey');
    $key = hm_post('key');
    $password = hm_post('password');
    $password2 = hm_post('password2');
    if ($password == $password2) {
        $tableName = DB_PREFIX . "field";
        $whereArray = array('name' => MySQL::SQLValue('lostpw_key'), 'object_type' => MySQL::SQLValue('user'), 'val' => MySQL::SQLValue($key));
        $hmdb->SelectRows($tableName, $whereArray);
        $row = $hmdb->Row();
        $user_id = $row->object_id;
        $salt = rand(100000, 999999);
        $password_encode = hm_encode_str(md5($password . $salt));
        $tableName = DB_PREFIX . "users";
        $updateArray = array('user_pass' => MySQL::SQLValue($password_encode), 'salt' => MySQL::SQLValue($salt));
        $whereArray = array('id' => MySQL::SQLValue($user_id, MySQL::SQLVALUE_NUMBER));
        $hmdb->UpdateRows($tableName, $updateArray, $whereArray);
        return json_encode(array('status' => 'success', 'mes' => _('Đã đổi mật khẩu thành công')));
    } else {
        return json_encode(array('status' => 'error', 'mes' => _('Hai mật khẩu bạn nhập vào không khớp')));
    }
}
Ejemplo n.º 2
0
 /**
  * Metodo per inserire immagine al prodotto
  * 
  * @param String $img_1 Nome dell'immagine del file
  * @param int $position position immagine
  * @param int $id_product Id del prodotto
  */
 function insertProductImage2($img_1, $position, $id_product)
 {
     if (file_exists(FOLDER_UNZIP . $img_1)) {
         $values['id_product'] = MySQL::SQLValue($id_product);
         $values['position'] = MySQL::SQLValue($position);
         if ($position > 1) {
             $values['cover'] = MySQL::SQLValue(0);
         } else {
             $values['cover'] = MySQL::SQLValue(1);
         }
         $db = new MySQL();
         $first_img_id = $db->InsertRow("ps_image", $values);
         foreach ($this->ecommerce_lang_by_erp as $erp_lang => $ps_id_lang) {
             $values_img['id_image'] = MySQL::SQLValue($first_img_id);
             $values_img['id_lang'] = MySQL::SQLValue($ps_id_lang);
             $values_img['legend'] = MySQL::SQLValue(NULL);
             $db->InsertRow("ps_image_lang", $values_img);
         }
         $values_shop['id_image'] = MySQL::SQLValue($first_img_id);
         $values_shop['id_shop'] = MySQL::SQLValue(1);
         if ($position > 1) {
             $values_shop['cover'] = MySQL::SQLValue(0);
         } else {
             $values_shop['cover'] = MySQL::SQLValue(1);
         }
         $db->InsertRow("ps_image_shop", $values_shop);
         $char_1 = $this->addImageToFolder($first_img_id);
         @mkdir(FOLDER_PS_IMAGE . $char_1, 0777, TRUE);
         $array_extension = explode(".", $img_1);
         $this->unlinkImageProduct(FOLDER_PS_IMAGE . $char_1 . "/" . $first_img_id);
         copy(FOLDER_UNZIP . $img_1, FOLDER_PS_IMAGE . $char_1 . "/" . $first_img_id . ".jpg");
         if (defined('PRODUCTS_GROUP_BY_IMAGE') and PRODUCTS_GROUP_BY_IMAGE == 1) {
             if ($position == 1) {
                 $values_image_group = null;
                 $values_image_group['id_product'] = MySQL::SQLValue($id_product);
                 $values_image_group['image_name'] = MySQL::SQLValue($img_1);
                 $values_image_group['parent'] = MySQL::SQLValue($this->checkIfParentExits($img_1));
                 if ($this->checkIfAlreayExistsGroupPrID($id_product)) {
                     $where['id_product'] = MySQL::SQLValue($id_product_);
                     $values_update_image_group['image_name'] = MySQL::SQLValue($img_1);
                     $db_image_group = new MySQL();
                     $db_image_group->UpdateRows("erp_image_group", $values_update_image_group, $where);
                 } else {
                     $db_image_group = new MySQL();
                     $db_image_group->InsertRow("erp_image_group", $values_image_group);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
/** Load template user box */
function ajax_ban_user()
{
    $id = hm_post('id');
    if (isset_user($id) == TRUE) {
        $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
        $tableName = DB_PREFIX . "users";
        $whereArray = array('id' => $id);
        $values['user_role'] = MySQL::SQLValue(5, MySQL::SQLVALUE_NUMBER);
        $hmdb->UpdateRows($tableName, $values, $whereArray);
    }
}
function taxonomy_delete_permanently($id)
{
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    hook_action('taxonomy_delete_permanently');
    if (isset_taxonomy_id($id) == TRUE) {
        $tableName = DB_PREFIX . "taxonomy";
        /* update lại parent các sub taxonomy */
        $valuesArray = array('parent' => MySQL::SQLValue(0));
        $whereArray = array('parent' => MySQL::SQLValue($id));
        $hmdb->UpdateRows($tableName, $valuesArray, $whereArray);
        /* xóa bảng taxonomy */
        $whereArray = array('id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng field */
        $tableName = DB_PREFIX . "field";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('taxonomy'));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng relationship */
        $tableName = DB_PREFIX . "relationship";
        $whereArray = array('object_id' => MySQL::SQLValue($id));
        $hmdb->DeleteRows($tableName, $whereArray);
        /* xóa bảng request uri */
        $tableName = DB_PREFIX . "request_uri";
        $whereArray = array('object_id' => MySQL::SQLValue($id), 'object_type' => MySQL::SQLValue('taxonomy'));
        $hmdb->DeleteRows($tableName, $whereArray);
    }
}
Ejemplo n.º 5
0
 /**
  * Metodo utilizzato per leggere le informazioni da ERP
  * e inserirle nella tabella vsecommerce_info
  */
 function readInfoEcommerce()
 {
     $content = $this->file_get_contents_utf8(FOLDER_UNZIP . FILE_INFO . ".txt");
     $array_field = explode("\n", $content);
     if ($this->checkInsertOrAppend(FILE_INFO) == 0) {
         $this->truncateTable("vsecommerce_info");
     }
     foreach ($array_field as $field_comb) {
         $data = explode("§", $field_comb);
         if (!$this->checkInfoExists(trim($data[0]))) {
             $values['field_name'] = MySQL::SQLValue(trim($data[0]));
             $values['value'] = MySQL::SQLValue(trim($data[1]));
             $db = new MySQL();
             $db->InsertRow("vsecommerce_info", $values);
         } else {
             $where['field_name'] = MySQL::SQLValue(trim($data[0]));
             $values['value'] = MySQL::SQLValue(trim($data[1]));
             $db = new MySQL();
             $db->UpdateRows("vsecommerce_info", $values, $where);
         }
     }
 }
Ejemplo n.º 6
0
 function refreshCustomer($id_cust, $firstname, $lastname, $company, $fido, $utilizzo)
 {
     $values = null;
     if (!empty($firstname)) {
         $values['firstname'] = MySQL::SQLValue($firstname);
     } else {
         $values['firstname'] = MySQL::SQLValue("-Senza Nome-");
     }
     if (!empty($lastname)) {
         $values['lastname'] = MySQL::SQLValue($lastname);
     } else {
         $values['lastname'] = MySQL::SQLValue(htmlentities("-Senza Cognome-"));
     }
     if (!empty($company)) {
         $values['company'] = MySQL::SQLValue($company);
     } else {
         $values['company'] = MySQL::SQLValue(htmlentities("-Senza Ragione Sociale-"));
     }
     if (!empty($utilizzo)) {
         $values['outstanding_allow_amount'] = MySQL::SQLValue(str_replace(",", ".", $fido) - str_replace(",", ".", $utilizzo));
     } else {
         $values['outstanding_allow_amount'] = MySQL::SQLValue(str_replace(",", ".", $fido));
     }
     $where['id_customer'] = MySQL::SQLValue($id_cust);
     $db = new MySQL();
     $db->UpdateRows("ps_customer", $values, $where);
 }
Ejemplo n.º 7
0
 /**
  * Metodo per aggiornare le etichette di una categoria già esistente
  * Parametri
  * @param $arraCat Array della categoria passato da ERP
  * @param $id_category Id della categoria già presente nel DB di Prestashop
  * @param $lang Array contenente le etichette per la categoria
  *
  */
 function updateCategoryLang($arraCat, $id_category, $lang)
 {
     foreach ($this->commerce_lang_by_erp as $erp_lang => $ps_id_lang) {
         $values = NULL;
         $values['id_shop'] = MySQL::SQLValue(1);
         $values['id_lang'] = MySQL::SQLValue($ps_id_lang);
         if (!empty($lang[$erp_lang])) {
             $values['name'] = MySQL::SQLValue(str_replace("’", "'", $lang[$erp_lang]));
         } else {
             // recupero il valore di default della lingua che deve essere usato
             if (!empty($lang[$this->ecommerce_lang_by_erp[$this->default_language_ecommerce]])) {
                 $values['name'] = MySQL::SQLValue(str_replace("’", "'", $lang[$this->ecommerce_lang_by_erp[$this->default_language_ecommerce]]));
             } else {
                 if (isset($arraCat[2]) and !empty($arraCat[2])) {
                     $values['name'] = MySQL::SQLValue(str_replace("’", "'", html_entity_decode(str_replace("à", "à", str_replace(" ", " ", str_replace("Ã", "à", htmlentities(str_replace("à", "à", $arraCat[2]))))))));
                 } else {
                     $values['name'] = MySQL::SQLValue("-Categoria Senza Nome-");
                 }
             }
         }
         if (isset($arraCat[12]) and !empty($arraCat[12])) {
             $values['description'] = MySQL::SQLValue(mb_convert_encoding($arraCat[12], "HTML-ENTITIES", "UTF-8"));
         } else {
             if (isset($arraCat[2]) and !empty($arraCat[2])) {
                 $values['description'] = MySQL::SQLValue($arraCat[2]);
             } else {
                 $values['description'] = MySQL::SQLValue("-Categoria Senza Descrizione-");
             }
         }
         $values['link_rewrite'] = MySQL::SQLValue($this->slugify($arraCat[2]));
         $values['meta_title'] = MySQL::SQLValue(html_entity_decode(str_replace(" ", " ", str_replace("Ã", "à", htmlentities($arraCat[2])))));
         $values['meta_keywords'] = MySQL::SQLValue(" ");
         $values['meta_description'] = MySQL::SQLValue(" ");
         $db = new MySQL();
         $where['id_category'] = MySQL::SQLValue($id_category);
         $db->UpdateRows("ps_category_lang", $values, $where);
     }
 }
Ejemplo n.º 8
0
// Example to delete a row (or rows) in a table matching a filter
// =========================================================================
// Now let's delete that record using the same array for the WHERE clause
$db->DeleteRows("Test", $values);
// =========================================================================
// Example to update an existing row into a table
// =========================================================================
// Create an array that holds the update information
// $arrayVariable["column name"] = formatted SQL value
$update["Color"] = MySQL::SQLValue("Red");
$update["Age"] = MySQL::SQLValue(123, MySQL::SQLVALUE_NUMBER);
// Create a filter array the detemrines which record(s) to process
// (you can specify more than one column if needed)
$where["TestID"] = MySQL::SQLValue(1, "integer");
// Execute the update
$result = $db->UpdateRows("test", $update, $where);
// If we have an error
if (!$result) {
    // Show the error and kill the script
    $db->Kill();
}
// --------------------------------------------------------------------------
// FYI: We can also shortcut and specify the "where" array in the call...
if (!$db->UpdateRow("test", $values, array("TestID" => 1))) {
    $db->Kill();
}
// =========================================================================
// Here's a standard SQL query INSERT
// =========================================================================
// Build the INSERT SQL statement...
// (this could also be an UPDATE or DELETE SQL statement)
Ejemplo n.º 9
0
/** Ajax đổi tên nhóm media */
function rename_media_group($args = array())
{
    if (!is_array($args)) {
        parse_str($args, $args);
    }
    $hmdb = new MySQL(true, DB_NAME, DB_HOST, DB_USER, DB_PASSWORD, DB_CHARSET);
    $group_name = $args['group_name'];
    $group_id = $args['group_id'];
    $tableName = DB_PREFIX . 'media_groups';
    $valuesArray = array('name' => MySQL::SQLValue($group_name));
    $whereArray = array('id' => MySQL::SQLValue($group_id));
    return $hmdb->UpdateRows($tableName, $valuesArray, $whereArray);
}
Ejemplo n.º 10
0
 public function update($data, $id)
 {
     $db = new MySQL(true, 'color64', 'localhost', 'color64', 'nu5Jc4JdtZK4RCHH');
     $db->UpdateRows('users', $data, 'id = ' . $id);
 }