Re: PHP database syntax/construct: can we make it better?
| From: | rasmus at lerdorf dot on dot ca | Date: | Tue, 11 Jul 2000 21:08:25 +0000 |
| Subject: | Re: PHP database syntax/construct: can we make it better? | ||
| References: | 1 | Groups: | php.dev php.general |
| Request: | Send a blank email to php-dev+get-24223@lists.php.net to get a copy of this message | ||
You are getting into templating again. Just create an SQL() function.
I don't see why:
<HOST = "my_host">
<USER = "my_name">
<PASS = "my_pass">
<DB = "my_db">
<SQL "select first,last,addr from my_table">
$first, $last, $addr<br>
</SQL>
is any cleaner than:
<?
$HOST = "my_host";
$USER = "my_name";
$PASS = "my_pass";
$DB = "my_db";
SQL("select first,last,addr from my_table",
'$first, $last, $addr<br>');
?>
This is trivial to implement in user-space. And it is even
DTD-friendly. Your <SQL> <HOST> stuff is an absolute nightmare from any
sort of standards perspective.
-Rasmus
On Tue, 11 Jul 2000, Monte Ohrt wrote:
> One thing about PHP that has always been kind of difficult is the way it
> accesses databases. I'm not necessarily talking about abstraction, but
> the way the syntax works which is mostly inherited from the PHP language
> structure.
>
> Here is an example of what I mean. I'll give one example of how PHP does
> a database query, and then a comparison to the way another "html-ish"
> scripting language accomplishes the same task.
>
> Example: selecting and displaying rows from a database.
>
> ---PHP:---
>
> <?
>
> $link = mysql_connect("my_host","my_name","my_pass");
> mysql_select_db("my_db",$link);
>
> $result = mysql_query("select first,last,addr from my_table",$link);
>
> while($row = mysql_fetch_row($result) {
> printf("%s, %s, %s<br>\n",$row[0],$row[1],$row[2]);
> }
>
> echo "there were ".mysql_num_rows($result)." records found.<br>\n";
>
> ?>
>
>
> ---OTHER HTML-TYPE LANGUAGE:---
>
>
> <HOST = "my_host">
> <USER = "my_name">
> <PASS = "my_pass">
> <DB = "my_db">
>
> <SQL "select first,last,addr from my_table">
> $first, $last, $addr<br>
> </SQL>
> There were $loop records found.
>
>
>
>
> Of course each syntax has it's pros and cons. PHP is much more
> extensible, but the latter is quite easy to read and quick to implement
> without the need to construct for() and while() loops. Is there any way
> to make PHP a bit easier to work with, instead of constantly having to
> create while loops, calling functions for simple things like number of
> rows fetched, etc.? Any good way to implicitly automate this?
>
> I have some ideas, but they require modifying the fundamental PHP
> language construct.
>
> I have attached those thoughts below. Any other ideas, or do we just
> deal with what we have?
>
> Monte