php - Duplicating a mysql row with null variables -


I have a table with multiple columns I have a function that has an update in my new line Duplicated with auto-incremented ID.

The function, however, on some of my INT columns, sometimes I have a tap as the default when the record is repeated, it changes my null placement to 0.

I am assuming this because I am assuming "code". ''

Can anyone help me how i value zero value ".null." I can include as and my other values ​​are ''. Value '. '?

Edit I am having trouble in differentiating a null and a blank value. I have tried empty () and is_null () and with no value a varchar and INT is not showing a difference with a zero value

Note : < em> I understand that I am using an old MySQL extension. For now, I'm just trying to process my tap variable properly. Function DuplicateTorrent ($ table, $ id_field, $ id_value) {// Copy copy of the record you wish to clone $ unit = mysql_fetch_array (mysql_query ("Select * From {$ table} where {$ id_field} = {$ id_value} "), MYSQL_ASSOC) or die (" Could not select original record "); // Automatically set the value of the increased IDs to clear if you forget this step, then nothing will work because we do not have two records with the same ID $ unit [$ id_field] = "" Can; // Original record mysql_query ("INSERT INTO {$ table}" (".implode (", ", array_keys ($ unit).") Value ('' .implode ('', '', clone copy of array_values Inserted ($ institution)). "') Or die (mysql_error ()); // returns the new id mysql_insert_id ();}

You do not need to bring data into PHP only to send it back to MySQL: A single SQL command that basically resides within Shebang database Enables you to move.

However, you need to exclude $ id_field from the operation, so you can not use the * wildcard but instead the column names should be clearly listed. It combines some complexity, especially for operation in a safe, injection-proof way:

  function duplicate ($ table $ id_field, $ id_value) {// SQL injection Stop $ enc_map = array ('utf8' = & gt; 'UTF-8', 'latin1' = & gt; 'Windows-1252' // etc); mb_regex_encoding ($ enc_map [mysql_client_encoding ()]); $ Table_safe = '`' .mb_ereg_replace ('`', '``, $ table).' `'; $ Id_field_safe = '`' .mb_ereg_replace ('`', '``, $ id_field).' `'; $ id_value_safe = mysql_real_escape_string ($ id_value); // Column column name $ fields = array (); $ qry = mysql_query ("Show saved COLUMNS from table table"); While ($ line = mysql_fetch_assoc ($ qry)) ($ line ['field'] = $ id_field) $ field [] = '`' .mb_ereg_replace ('`', '`', $ row ['field]'] ). ' ''; $ Fields_safe = implode (',', $ fields); // record mysql_query copy ("$ table_safe ($ fields_safe) inserting $ fields_safe selection from $ table_safe ou $ id_field_safe = '$ id_value_safe'"); // returns the new id mysql_insert_id (); }   

Note that the ancient ext / mysql extension has been deprecated and its use in the new code has been frustrating over the years. You should consider switching seriously to either.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -