Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
Oracle Discussion & Chat
 PHP Code: Update MySQL Table Using An Array Jump to:  
Category: >> PHP Code >> Update MySQL Table Using An Array Bookmark and Share

<< lastnext >>

Snippet Name: Update MySQL Table Using An Array

Description: Iterate over an array and update a mySQL table.

Comment: (none)

Language: PHP, MYSQL
Highlight Mode: PHP
Last Modified: March 01st, 2009

// Parameters:
// Table: Name of table to update
// Data: array of $field->$value with new values
// Id Field: Name of field to use as ID field
// Id Value: Value of ID field
FUNCTION mysql_update_array($table, $data, $id_field, $id_value) {
     FOREACH ($data AS $field=>$value) {
          $fields[] = SPRINTF("`%s` = '%s'", $field, MYSQL_REAL_ESCAPE_STRING($value));
     $field_list = JOIN(',', $fields);
     $query = SPRINTF("UPDATE `%s` SET %s WHERE `%s` = %s", $table, $field_list, $id_field, INTVAL($id_value));
     RETURN $query;

Oracle Magazine
and Oracle White Papers

SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 32 users online    © 2009 psoug.org

Forgot your password?