Forum Moderators: coopster

Message Too Old, No Replies

MySQL queries from within a SOAP server

how best to format the query function?

         

lorax

9:29 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've got a SOAP server that has several functions within it. Each one queries the database and returns data to the SOAP client.

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?

coopster

10:29 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, I'm not real sure about this, lorax, and I have absolutely zero experience using the MySQL persistent database connections (disclaimer intended ;) ). However, I would be hesitant to use mysql_pconnect simply because of the Note and the Warning on the bottom of the manual pages [php.net]. You may also want to read the link from there that describes Persistent Database Connections [php.net].

lorax

8:02 pm on Dec 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Funny you should mention that Coopster. I chose not to do persistent connections for exactly those reasons but I couldn't help but think I might be missing out on something.

Got any insight/thoughts on using a mysql_connect within each of the functions?

coopster

12:16 am on Dec 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Not really. I really wish I could offer some sort of significant contribution here, but I can't -- sorry, pal, I wish I could help. About the only insight I could offer would be this...

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]...?