I have a number of encoded polylines stored in separate database records. I can successfully retrieve each one, decode it and create a single KML file. However, I need to create a KML file that includes all polylines. What I've discovered is that the syntax for both geojson (my intermediate step) and KML are drastically different when you have more than one line segment. None of the libraries I've found create MultiLineStrings (http://geojsonlint.com/#sample-MultiLineString) and the tokml library (https://github.com/mapbox/tokml) doesn't seem to support them as an input anyway.
PolyGeo is spot on asking for more information but I will take a stab at this anyway. By the sounds of it, you are extracting each line from the database singly. I'd recommend doing a bulk operation using ogr2ogr. This way you should be able to read the database and export all lines in one go to KML (or any other format supported by ogr2ogr) with no need of an intermediate step. Here's a tutorial.