John Taylor-Johnston <mailto:[EMAIL PROTECTED]>
    on Saturday, August 16, 2003 5:19 PM said:

> Have I over done this?

That I don't know.

> Can I clean up this code any?

Yes.

1. You can take your open/closeserver() functions one step farther and
create a query function (can be called something like dbQuery()).
Anytime you repeat code you should look into a way of turning that
repeating code into a function. For example you seem to follow this:

OpenServer();
$sql = "SELECT mystuff";
mysql_query($sql) or die(..);
CloseServer();

Turn that into a function instead and save yourself the hassle of typing
mysql_query(..) or die(..);


Function myQuery($sql)
{
        OpenServer();
        mysql_query($sql) or die(..);
        CloseServer();
}

Now all you have to do is this:

$sql = "SELECT mystuff";
myQuery($sql);

2. Only because it's redundant, you shouldn't Open/CloseServer() in each
code block. Instead, OpenServer() and the beginning of the page and
CloseServer() at the end of the page.


<?
        OpenServer();

// entire page content goes here

        CloseServer();
?>

That would turn the function I wrote above into this:

Function myQuery($sql)
{
        mysql_query($sql) or die(..);
}

3. In my limited experience with php I would recommend you create a
database class that will organize all your db functions into one object.
Shoot me an email offlist if you'd like to see what I've written.



HTH,
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to