Forum Moderators: coopster
A sample function within the SOAP server looks like this:
function getpricing($mn) {
$db = mysql_connect("mydomain", "uname", "pwd") or die("Could not connect to the database.");
$usedb = mysql_select_db("dbname", $db);
$query = "SELECT products_price
FROM products
WHERE products_model = '".$mn."'";
$result = mysql_query($query)
or die("Could not retrieve current product from db: ".mysql_error());
$rbc = mysql_fetch_array($result)
or die("Could not display current product for you: ".mysql_error());
$page = $rbc[products_price];
return $page;
}
My questions:
Is it wise/necessary to do a mysql_connect within each function?
Should I use a pconnect instead or is that a waste of resources when using SOAP?
HTTP is a stateless protocol. We write scripts that read from a database, write output strings and send the file back off to the user agent. The user makes changes or selects something and off to the server we go again. Once again, our scripts are making new connections to our database and processing data. It's a cycle within dynamic web sites that happens more often than we could imagine. Think about what is happening on template-driven sites!
There, that might make you feel better about connecting every time ;)
Meanwhile, maybe you can find some help from the PHP SOAP Mailing List [php.net]...?