What you could do is have your clients use something like the following:
<?php
$username = clients_user_name;
get_file_contents('http://yoursite.com/bannerexchange.php');
?>
Then contain all of your code in bannerexchange.php. You can do all of your database work in that file, then simply "echo" out the code to display the image...
The only problem with that, is your client's site will have to be a PHP page...
There's obviously other ways to do it, but that might get you started.
This is some code that I use through ValueClick to load ads from their database on one of my websites... it might help you, don't know...
<!-- VC active -->
<SCRIPT LANGUAGE="JavaScript">
<!--
// ValueParameters
ValueHost = "YOURHOSTID";
ValueLoaded = false;
ValueID = "THEVALUEID";
ValueVersion = "1.1";
ValueBannerType = "std";
ValueWidth = 120;
ValueHeight = 240;
//-->
</SCRIPT>
<SCRIPT LANGUAGE="Javascript" SRC="http://oz.valueclick.com/jsmaster"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
if (ValueLoaded) ValueShowAd();
//-->
</SCRIPT>
<!-- vc active -->
<NOSCRIPT>
<A HREF="http://oz.valueclick.com/redirect?host=YOURHOSTID&size=120x240&t=std&b=indexpage&v=0" TARGET="_top"><IMG BORDER="0" WIDTH="120" HEIGHT="240" ALT="Click here to visit our sponsor"
SRC="http://oz.valueclick.com/cycle?host=YOURHOSTID&size=120x240&t=std&b=indexpage&noscript=1"></A>
</NOSCRIPT>
That obviously doesn't require the client to be PHP based...