Re: Re: PHP database syntax/construct: can we make it better?
| From: | Chris Adams | Date: | Wed, 12 Jul 2000 15:23:02 +0000 |
| Subject: | Re: Re: PHP database syntax/construct: can we make it better? | ||
| References: | 1 2 | Groups: | php.dev php.general |
| Request: | Send a blank email to php-dev+get-24323@lists.php.net to get a copy of this message | ||
> I understand that the syntax given in the example is non-standards
> compliant, I wouldn't suggest using that syntax in PHP itself. I can
> make an SQL() function which performs the functionality in the example,
> but its not too extensible beyond displaying the data row by row. I've
> tried making my own classes & functions for this, but there isn't a way
> to encapsulate functionality like so:
>
> sql_start();
> // do something here for each iteration
> sql_end();
There's a very easy way to do this - it's called eval. It'd be trivial to
write a class that does something like:
$query->connect($Host, $Username, $Password);
$query->execute('SELECT Name, Price FROM Products');
$query->display('<TR><TD>$Name</TD><TD>$Price</TD></TR>');
The only thing cold fusion (which is the most common example of the query
syntax you mention) does which is worth emulating is the DSN behaviour. I
really like being able to have a single point to configure *all* of the
database options, including things like details of the connection pooling
mechanism and restricting SQL to certain query types (e.g. during a server
move it can be handy to allow only SELECTs on the tables you're copying).
Everything else is arguing over semantics and I don't see how this:
$query = mysql_query("SELECT Name, Price FROM Products");
while (list($Name, $Price) = mysql_fetch_row($query)) {
echo "$Name is priced at $Price";
}
is much worse than this:
<CFQUERY NAME="ProductListing" DATASOURCE="#DSN#">
SELECT Name, Price FROM Products
</CFQUERY>
<CFLOOP QUERY="ProductListing">
<CFOUTPUT>
#Name# is priced at #Price#
</CFOUTPUT>
</CFLOOP>