Re: PHP database syntax/construct: can we make it better?
| From: | Doug Semig | Date: | Tue, 11 Jul 2000 21:40:54 +0000 |
| Subject: | Re: PHP database syntax/construct: can we make it better? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6018@lists.php.net to get a copy of this message | ||
If you're going to go through all the bother, why even have an sql_init
function? Just pass the info that sql_init() was to get within the
$sql_params array and make the sql_start()...sql_end() construct smart
enough to maintain the connection.
For that matter, since it's a language construct a lot more than it is just
a few extra functions, you could design the construct in a slightly
different manner:
<?
$empcount = 0;
$sql_statement = "SELECT firstname, lastname, company FROM mytable";
sql ("host", "username", "password", "dbtype",
$sql_statement [,
$sql_params_array ]) {
echo $firstname . ", " . $lastname . ", " . $company .
"<BR>\n";
$empcount++;
}
echo "There are " . $empcount . " employees listed in the above
table.<BR>\n";
?>
I included the $empcount lines to show freely intermingling stock PHP
within the loop created by the currently fictitious sql() construct. The
$firstname, $lastname, and $company variables are automagically generated
within the implied loop within the sql() construct, and would be destroyed
when leaving the construct--their scope would be local to the construct only.
The optional $sql_params_array would be where you put those additional
features that aren't required for the operation of the built-in loop, but
only modify the operation of the loop. However, I didn't understand what
you meant by "row accumulation". I did understand what you meant by
limiting the number of rows, though, but those depend upon values that must
exist outside of the construct when it is run...so those may be best left
to stock PHP to adjust LIMIT clauses when building the SQL statement itself
before using the construct.
Just some ideas for you.
Doug
Monte Ohrt was heard at 03:59 PM 7/11/00 -0500 to say:
... snip ...
><?
>
> $id = sql_init("host","username","password","db");
> $sql_params = array( "query" => "select firstname,lastname,company from
my_table" );
>
> sql_start($id,$sql_params);
>
> echo "$firstname, $lastname, $company<br>\n";
>
> sql_end($id);
>
>?>
>
... snip ...