numeric && !$fields[$field]->timestamp && !$fields[$field]->blob) { $values[] = $value; } // A true BLOB // - mysqldump only generates hex data when the --hex-blob // option is used, for fields having the binary attribute // no hex is generated // - a TEXT field returns type blob but a real blob // returns also the 'binary' flag else if ($fields[$field]->binary && $fields[$field]->blob) { // Empty blobs need to be different, but '0' is also empty :-( if (empty($value) && $value != '0') { $values[] = "''"; } else { $values[] = '0x' . bin2hex($value); } } // Something else -> treat as a string else { $values[] = "'" . str_replace($search, $replace, $value) . "'"; } $field++; } if ($current_row == 1) { $insert_buffer = $insert_cmd . '(' . implode(', ', $values) . ')'; } else { $insert_buffer = '(' . implode(', ', $values) . ')'; if ($query_size + strlen($insert_buffer) > 50000) { $output .= ";\n"; $current_row = 1; $query_size = 0; $insert_buffer = $insert_cmd . $insert_buffer; } } $query_size += strlen($insert_buffer); $output .= ($current_row == 1 ? '' : ",\n") . $insert_buffer; } if ($current_row > 0) { $output .= ";\n"; } // Enable indices again. $output .= "/*!40000 ALTER TABLE $table ENABLE KEYS */;\n"; } return $output; } /** * Return table fields and their properties. */ function _demo_get_fields($result) { $fields = array(); switch ($GLOBALS['db_type']) { case 'mysql': $num_fields = mysql_num_fields($result); for ($i = 0; $i < $num_fields; $i++) { $meta = mysql_fetch_field($result, $i); // Enhance field definition with custom properties. $meta->timestamp = (int)($meta->type == 'timestamp'); $flags = mysql_field_flags($result, $i); $meta->binary = (int)(stristr($flags, 'binary') !== FALSE); $fields[] = $meta; } break; case 'mysqli': while ($meta = mysqli_fetch_field($result)) { // Enhance the field definition for mysql-extension compatibilty. $meta->numeric = (int)(bool)($meta->flags & MYSQLI_NUM_FLAG); $meta->blob = (int)(bool)($meta->flags & MYSQLI_BLOB_FLAG); // Add custom properties. $meta->timestamp = (int)($meta->type == MYSQLI_TYPE_TIMESTAMP); $meta->binary = (int)(bool)($meta->flags & MYSQLI_BINARY_FLAG); $fields[] = $meta; } break; } return $fields; }