Posted By

ginoplusio on 01/25/10


Tagged

mysqlphpduplicateinsert


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ginoplusio


Duplicate one row in a MYSQL table through PHP


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/01/25/10-php-usefull-functions-for-mysql-stuff/

  1. function duplicateRow($table,$primaryField,$primaryIDvalue) {
  2. // duplicate one record in a table
  3. // and return the id
  4. $fields = getCommaFields($table,$primaryField);
  5. $sql = "insert into $table ($fields) select $fields from $table where $primaryField='".mysql_real_escape($primaryIDvalue)."' limit 0,1";
  6. mysql_query($sql) or die(mysql_error().$sql);
  7. return mysql_insert_id();
  8. }

Report this snippet  

You need to login to post a comment.