See also the "See also" on the page in Pierre's answer, in particular exec() and backtick operator. Other things to think about:
Whether you want the output returned as a variable, or not, calling external programs can be a security hole unless you're careful. Long processes will hang the browser (if you're writing for the web), so use shell_exec() if that's an issue
EDIT: I just noticed the "connect to database" part of your question. I'm unsure what you mean. If you want to store the clustalw results in a database, I guess you need parser code too, unless you plan to store all the output in one field.
Once you have the ClustalW results using system command as explained by Pierre, I would recommend to use MView for visualization in HTML. It's a neat command line tool that can generate pretty HTML from alignment (BLAST, ClustalW and other alignment programs) files. Once you have the HTML you can be print on to your PHP code on the fly. You can download MView from sourceforge.