We do not know exactly who said this, but we can know for sure where this quote is found. It is found in what Christians call the Old Testament, in the book of Ecclesiastes. Specifically, it is found in Ecclesiastes Chapter 12 Verse 13.
Now, as far as who said this, we do not know for sure. This is because we do not know who actually wrote this book of the Bible. There are scholars who believe that the writer of the book was King Solomon because the author identifies himself as the son of King David. However, not all scholars believe that King Solomon actually wrote this book.
So, it is not clear who said this line, but the line clearly comes from whoever wrote the book of Ecclesiastes.