Well... the title says it all really...
I am an intern at a company that specializes in back-ends of websites (a dream internship BTW

) plus I am also in the process of building my own website.
All of this with PHP and MySQL databases.
Now in my internship I often run into the problem that I want to do something and I know it's already out there, Open Source. But I believe the GPL restricts you from using Open Source code in closed source software. So I have to reinvent the wheel constantly. Fortunately at my current internship I am working on an existing piece of code where things like MySQL database connections, querybuilding, tablebuilding etc. is already dealt with.
But what if my next internship isn't? What if I want to make a website with a decent back-end freelance style to sell?
Should I start building my own PHP library that I can use for work and for my private use, simply because I own the intellectual copyright? Is that even legal? Or desirable for that matter?
Could I make it open source but in such a way that I could still use it in closed source myself and companies I work for?
Does anyone have any experiance or expertise on these matters?