Re: a script that connects to database
In the most general sense, the things that happen in your database usually happen using your credentials, not the users' credentials, so that part's not a worry. Whether your users are authenticated or not (your choice, but I wouldn't usually let unauthenticated users do anything scarier than leave a comment on a blog), they will usually be the "same" user at the level of database interaction, even if they are different at the level of your application.
That said, we don't know enough about what you want to do in order to be of much real help. All we can do is point you to the general case of PHP interacting with MySQL using, say, PHP Data Objects (PDO), but that leaves an awful lot of work for you to do. (Not that learning the whole field wouldn't be tremendously rewarding -- it would be -- but it doesn't get you much closer to your goal in the short term.) So can you elaborate on what you want to accomplish?
“Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
"It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)